finalizando trab 2

This commit is contained in:
2023-09-12 11:21:31 -03:00
parent 9fafd82b5c
commit 428122f04e
4 changed files with 160 additions and 97 deletions
+26 -4
View File
@@ -1,7 +1,29 @@
from hashlib import sha256
import time
# password = hashed password
def generate_token(password, salt):
time = time.strftime('%d%m%Y%H%M')
token = sha256((password + salt + time).encode('utf-8')).hexdigest()
# token = hashed password + hashed salt
def generate_token(token):
time = get_timestamp()
token = sha256((token + time).encode('utf-8')).hexdigest()
return token
# password = hashed seed password
# salt = hashed salt
def get_salted_password(password, salt):
return sha256((password + salt).encode('utf-8')).hexdigest()
def validate_token(salted_password, token, n=5):
time = get_timestamp()
tokens = []
for i in range(n):
last = tokens[-1] if len(tokens) > 0 else salted_password
tokens.append(generate_token(last))
if token[:8] == tokens[-1][:8]:
return True, i
return False, -1
def get_timestamp():
return time.strftime('%d%m%Y%H%M')