Skip to content

Instantly share code, notes, and snippets.

View fusionking's full-sized avatar

Can Arsoy fusionking

  • Picnic
View GitHub Profile
@valaparthvi
valaparthvi / django_otp_token_generation.py
Last active November 28, 2022 08:53
Generate and Verify Time-based OTP with django-otp.
from django_otp.oath import TOTP
from django_otp.util import random_hex
from unittest import mock
import time
class TOTPVerification:
def __init__(self):
# secret key that will be used to generate a token,
@ibeex
ibeex / auth.py
Created October 14, 2011 20:04
Python LDAP (ActiveDirectory) authentication
import ldap
def check_credentials(username, password):
"""Verifies credentials for username and password.
Returns None on success or a string describing the error on failure
# Adapt to your needs
"""
LDAP_SERVER = 'ldap://xxx'
# fully qualified AD user name
LDAP_USERNAME = '%[email protected]' % username
@dcramer
dcramer / track_data.py
Created December 6, 2010 19:15
Tracking changes on properties in Django
from django.db.models.signals import post_init
def track_data(*fields):
"""
Tracks property changes on a model instance.
The changed list of properties is refreshed on model initialization
and save.
>>> @track_data('name')