fix stuff

This commit is contained in:
morales-gregorio 2024-08-26 11:03:02 +02:00
parent 095f4474b0
commit 8a07dbab02
2 changed files with 18 additions and 12 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
pwdb.json
__pycache__

29
auth.py
View file

@ -1,6 +1,8 @@
import json
import sys
pwdb_path = 'pwdb.json'
def get_credentials():
username = input('Enter your username: ')
password = input('Enter your password: ')
@ -25,18 +27,21 @@ def write_pwdb(pwdb, pwdb_path):
pwdb_file = open(pwdb_path, 'wt')
json.dump(pwdb, pwdb_file)
pwdb_path = 'pwdb.json'
pwdb = read_pwdb(pwdb_path)
def main():
pwdb = read_pwdb(pwdb_path)
if len(sys.argv) > 1:
pwdb = add_user(sys.argv[1], pwdb)
write_pwdb(pwdb, pwdb_path)
else:
username, password = get_credentials()
if username not in pwdb:
print('Wrong username!')
if len(sys.argv) > 1:
pwdb = add_user(sys.argv[1], pwdb)
write_pwdb(pwdb, pwdb_path)
else:
if authenticate(username, password, pwdb):
print('Successfully authenticated!')
username, password = get_credentials()
if username not in pwdb:
print('Wrong username!')
else:
print('Wrong password!')
if authenticate(username, password, pwdb):
print('Successfully authenticated!')
else:
print('Wrong password!')
if __name__=='__main__':
main()