expephalon-chat/totp/otp.py
Klaus-Uwe Mitterer d549897186 Too many things to remember all of them
Finally got the mail queue working
Oh yeah, queueing
Added a TOTP provider which doesn't do anything much yet
Probably a hell of a lot of other things that I just can't remember
2020-05-13 12:38:37 +02:00

29 lines
No EOL
699 B
Python

from core.classes.otp import BaseOTPProvider
from totp.models import TOTPUser
from dbsettings.functions import getValue
from django.utils import timezone
import pyotp
class TOTP(BaseOTPProvider):
@property
def get_name(self):
return "Time-based OTP"
@property
def is_active(self):
return True
def start_authentication(self, user):
return "Please enter the token displayed in your app."
def validate_token(self, user, token):
try:
otpuser = TOTPUser.objects.get(user=user)
return pyotp.TOTP(otpuser.secret).verify(token)
except OTPUser.DoesNotExist:
return False
OTPPROVIDERS = {"totp": TOTP}