2023-09-06 20:01:35 +00:00
|
|
|
from hashlib import sha256
|
2023-09-11 20:30:47 +00:00
|
|
|
import localtoken
|
2023-09-12 14:21:31 +00:00
|
|
|
import os
|
|
|
|
import time
|
2023-09-06 20:01:35 +00:00
|
|
|
|
|
|
|
def init_setup():
|
2023-09-12 14:21:31 +00:00
|
|
|
with open('gerador.dat', 'a', newline='') as setup:
|
2023-09-11 20:30:47 +00:00
|
|
|
user = input('Digite o usuário: ')
|
|
|
|
local_password = sha256(input('Digite a senha local: ').encode('utf-8')).hexdigest()
|
|
|
|
seed_password = sha256(input('Digite a senha semente: ').encode('utf-8')).hexdigest()
|
2023-09-12 21:09:54 +00:00
|
|
|
salt = sha256(input('Digite o salt: ').encode('utf-8')).hexdigest()
|
2023-09-12 14:21:31 +00:00
|
|
|
salted_password = localtoken.get_salted_password(seed_password, salt)
|
2023-09-06 20:01:35 +00:00
|
|
|
|
2023-09-12 14:21:31 +00:00
|
|
|
line = f'{user},{local_password},{salted_password}\n'
|
|
|
|
setup.write(line)
|
|
|
|
|
|
|
|
print(f'Usuário [{user}] registrado com sucesso!')
|
2023-09-06 20:01:35 +00:00
|
|
|
|
2023-09-11 20:30:47 +00:00
|
|
|
def generate_token():
|
2023-09-12 14:21:31 +00:00
|
|
|
user = input('Digite o usuário: ')
|
|
|
|
local_password = sha256(input('Digite a senha local: ').encode('utf-8')).hexdigest()
|
|
|
|
salted_password = ''
|
|
|
|
with open('gerador.dat', 'r', newline='') as setup:
|
|
|
|
for line in setup:
|
|
|
|
line = line.replace('\n', '')
|
2023-09-06 20:01:35 +00:00
|
|
|
|
2023-09-12 14:21:31 +00:00
|
|
|
if line.split(',')[0] == user and line.split(',')[1] == local_password:
|
|
|
|
salted_password = line.split(',')[2]
|
|
|
|
break
|
2023-09-06 20:01:35 +00:00
|
|
|
else:
|
|
|
|
print('Usuário ou senha incorretos!')
|
2023-09-12 14:21:31 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
loop_token(user, salted_password)
|
|
|
|
|
|
|
|
def loop_token(user, salted_password):
|
|
|
|
while True:
|
|
|
|
print(f'Gerando token para [{user}]...')
|
2023-09-12 21:09:54 +00:00
|
|
|
|
2023-09-12 14:21:31 +00:00
|
|
|
tokens = [localtoken.generate_token(salted_password)]
|
|
|
|
for i in range(4):
|
|
|
|
tokens.append(localtoken.generate_token(tokens[-1]))
|
|
|
|
|
|
|
|
for token in tokens:
|
|
|
|
print(token[:8])
|
|
|
|
|
|
|
|
time.sleep(60 - time.time() % 60 + 1)
|
|
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
|
|
|
|
def main():
|
|
|
|
while True:
|
|
|
|
print('Selecione uma opção:')
|
|
|
|
print('1 - Registrar usuário')
|
|
|
|
print('2 - Gerar token')
|
|
|
|
print('0 - Sair')
|
|
|
|
option = input('Opção: ')
|
|
|
|
|
|
|
|
if option == '1':
|
|
|
|
init_setup()
|
|
|
|
elif option == '2':
|
|
|
|
generate_token()
|
|
|
|
elif option == '0':
|
|
|
|
exit()
|
|
|
|
|
|
|
|
def exit():
|
|
|
|
print('Saindo...')
|
|
|
|
quit()
|
|
|
|
|
2023-09-06 20:01:35 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-09-12 14:21:31 +00:00
|
|
|
if not os.path.exists('gerador.dat'):
|
|
|
|
open('gerador.dat', 'w').close()
|
|
|
|
|
2023-09-06 20:01:35 +00:00
|
|
|
main()
|