hash the pass #13
					 1 changed files with 16 additions and 2 deletions
				
			
		
							
								
								
									
										18
									
								
								auth.py
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								auth.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
import json
 | 
			
		||||
import sys
 | 
			
		||||
from getpass import getpass
 | 
			
		||||
import hashlib
 | 
			
		||||
 | 
			
		||||
PWDB_PATH = 'pwdb.json'
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -10,10 +11,10 @@ def get_credentials():
 | 
			
		|||
    return (username, password)
 | 
			
		||||
 | 
			
		||||
def authenticate(username, password, pwdb):
 | 
			
		||||
    return password == pwdb[username]
 | 
			
		||||
    return pwhash(password) == pwdb[username]
 | 
			
		||||
 | 
			
		||||
def add_user(username, pwdb):
 | 
			
		||||
    pwdb[username] = input(f'Enter password for {username}: ')
 | 
			
		||||
    pwdb[username] = pwhash(input(f'Enter password for {username}: '))
 | 
			
		||||
    return pwdb
 | 
			
		||||
 | 
			
		||||
def read_pwdb(PWDB_PATH):
 | 
			
		||||
| 
						 | 
				
			
			@ -24,6 +25,19 @@ def read_pwdb(PWDB_PATH):
 | 
			
		|||
        pwdb = {}
 | 
			
		||||
    return pwdb
 | 
			
		||||
 | 
			
		||||
# def get_salt(username):
 | 
			
		||||
#     ''' will return a unique variable'''
 | 
			
		||||
 | 
			
		||||
#     salt = 
 | 
			
		||||
#     return salt
 | 
			
		||||
 | 
			
		||||
| 
					
	
 | 
			||||
 | 
			
		||||
def pwhash(password):
 | 
			
		||||
    hashed_pass = hashlib.sha256(password.encode('utf-8')).hexdigest()
 | 
			
		||||
    return hashed_pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def write_pwdb(pwdb, PWDB_PATH):
 | 
			
		||||
    pwdb_file = open(PWDB_PATH, 'wt')
 | 
			
		||||
    json.dump(pwdb, pwdb_file)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	
what is this?