fix trab 2 / finalizado
This commit is contained in:
parent
428122f04e
commit
8ce9fbd1f0
|
@ -8,7 +8,7 @@ def init_setup():
|
||||||
user = input('Digite o usuário: ')
|
user = input('Digite o usuário: ')
|
||||||
local_password = sha256(input('Digite a senha local: ').encode('utf-8')).hexdigest()
|
local_password = sha256(input('Digite a senha local: ').encode('utf-8')).hexdigest()
|
||||||
seed_password = sha256(input('Digite a senha semente: ').encode('utf-8')).hexdigest()
|
seed_password = sha256(input('Digite a senha semente: ').encode('utf-8')).hexdigest()
|
||||||
salt = input('Digite o salt: ')
|
salt = sha256(input('Digite o salt: ').encode('utf-8')).hexdigest()
|
||||||
salted_password = localtoken.get_salted_password(seed_password, salt)
|
salted_password = localtoken.get_salted_password(seed_password, salt)
|
||||||
|
|
||||||
line = f'{user},{local_password},{salted_password}\n'
|
line = f'{user},{local_password},{salted_password}\n'
|
||||||
|
@ -36,6 +36,7 @@ def generate_token():
|
||||||
def loop_token(user, salted_password):
|
def loop_token(user, salted_password):
|
||||||
while True:
|
while True:
|
||||||
print(f'Gerando token para [{user}]...')
|
print(f'Gerando token para [{user}]...')
|
||||||
|
|
||||||
tokens = [localtoken.generate_token(salted_password)]
|
tokens = [localtoken.generate_token(salted_password)]
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
tokens.append(localtoken.generate_token(tokens[-1]))
|
tokens.append(localtoken.generate_token(tokens[-1]))
|
||||||
|
@ -43,10 +44,7 @@ def loop_token(user, salted_password):
|
||||||
for token in tokens:
|
for token in tokens:
|
||||||
print(token[:8])
|
print(token[:8])
|
||||||
|
|
||||||
# sleep until next minute
|
|
||||||
time.sleep(60 - time.time() % 60 + 1)
|
time.sleep(60 - time.time() % 60 + 1)
|
||||||
|
|
||||||
# clear console
|
|
||||||
os.system('cls' if os.name == 'nt' else 'clear')
|
os.system('cls' if os.name == 'nt' else 'clear')
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -8,9 +8,9 @@ def register_user():
|
||||||
user = input('Digite o usuário: ')
|
user = input('Digite o usuário: ')
|
||||||
seed_password = sha256(input('Digite a senha: ').encode('utf-8')).hexdigest()
|
seed_password = sha256(input('Digite a senha: ').encode('utf-8')).hexdigest()
|
||||||
salt = ''.join(random.choice(string.ascii_letters) for i in range(16))
|
salt = ''.join(random.choice(string.ascii_letters) for i in range(16))
|
||||||
salt = sha256(salt.encode('utf-8')).hexdigest()
|
hashed_salt = sha256(salt.encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
line = f'{user},{seed_password},{salt}\n'
|
line = f'{user},{seed_password},{hashed_salt}\n'
|
||||||
with open('server.dat', 'a', newline='') as setup:
|
with open('server.dat', 'a', newline='') as setup:
|
||||||
setup.write(line)
|
setup.write(line)
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ def validate_token():
|
||||||
|
|
||||||
valid, index = localtoken.validate_token(password, token)
|
valid, index = localtoken.validate_token(password, token)
|
||||||
if valid:
|
if valid:
|
||||||
if used_index <= index and used_timestamp == localtoken.get_timestamp():
|
if index >= used_index and used_timestamp == localtoken.get_timestamp():
|
||||||
print('Chave inválida (invalidada)!')
|
print('Chave inválida (invalidada)!')
|
||||||
else:
|
else:
|
||||||
print('Chave válida!')
|
print('Chave válida!')
|
||||||
|
|
Loading…
Reference in New Issue