phash #17
					 1 changed files with 10 additions and 2 deletions
				
			
		
							
								
								
									
										12
									
								
								auth.py
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								auth.py
									
										
									
									
									
								
							|  | @ -1,6 +1,7 @@ | |||
| import json | ||||
| import sys | ||||
| from getpass import getpass | ||||
| import hashlib | ||||
| 
 | ||||
| PWDB_PATH = 'pwdb.json' | ||||
| 
 | ||||
|  | @ -10,12 +11,18 @@ def get_credentials(): | |||
|     return (username, password) | ||||
| 
 | ||||
| def authenticate(username, password, pwdb): | ||||
|     return password == pwdb[username] | ||||
|     return pwash(password) == pwdb[username] | ||||
| 
 | ||||
| def add_user(username, pwdb): | ||||
|     pwdb[username] = input(f'Enter password for {username}: ') | ||||
|     password = input(f'Enter password for {username}: ') | ||||
|     pwdb[username] = pwhash(password)     | ||||
|     return pwdb | ||||
| 
 | ||||
| def pwhash(password): | ||||
|     byte_pass = bytes(password, 'UTF-8') | ||||
|     hashed_password = hashlib.sha256() | ||||
|     hashed_password.update(byte_pass) | ||||
|     return str(hashed_password.digest()) | ||||
| def read_pwdb(PWDB_PATH): | ||||
|     try: | ||||
|         pwdb_file = open(PWDB_PATH, 'rt') | ||||
|  | @ -45,4 +52,5 @@ if __name__ == "__main__": | |||
|                 print('Successfully authenticated!') | ||||
|             else: | ||||
|                 print('Wrong password!') | ||||
|     pwhash(password) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue