2fa-0.7
This commit is contained in:
+19
-4
@@ -5,6 +5,7 @@ import re
|
||||
from onetimepass import valid_totp
|
||||
from secrets import choice
|
||||
import segno
|
||||
from os import path
|
||||
|
||||
class Tools():
|
||||
|
||||
@@ -47,12 +48,26 @@ class Tools():
|
||||
return(bool(re.fullmatch(regex, e)))
|
||||
|
||||
# 2FA
|
||||
def generate_secret(self): # Function to return a random string with length 16.
|
||||
def gen_qr(self, secret):
|
||||
if(not path.isfile('static/tmp/'+secret+'.png')):
|
||||
qrcode = segno.make(secret, micro=False)
|
||||
qrcode.save('static/tmp/'+secret+'.png', scale=10)
|
||||
|
||||
def gen_secret(self): # Function to return a random string with length 16.
|
||||
secret = ''
|
||||
while len(secret) < 16:
|
||||
secret += choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
|
||||
qrcode = segno.make(secret, micro=False)
|
||||
qrcode.save('static/tmp/'+secret+'.png', scale=10)
|
||||
self.gen_qr(secret)
|
||||
return secret
|
||||
|
||||
tools = Tools()
|
||||
def 2fa_validation(self, otp):
|
||||
authenticated = valid_totp(otp, secret)
|
||||
if authenticated:
|
||||
print('Correct otp, Authenticated!')
|
||||
return True
|
||||
elif not authenticated:
|
||||
print('Wrong otp, please try again.')
|
||||
return False
|
||||
|
||||
|
||||
Tools = Tools()
|
||||
|
||||
Reference in New Issue
Block a user