implement basic password hashing #11
					 1 changed files with 8 additions and 2 deletions
				
			
		
							
								
								
									
										10
									
								
								auth.py
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								auth.py
									
										
									
									
									
								
							| 
						 | 
					@ -10,10 +10,11 @@ def get_credentials():
 | 
				
			||||||
    return (username, password)
 | 
					    return (username, password)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def authenticate(username, password, pwdb):
 | 
					def authenticate(username, password, pwdb):
 | 
				
			||||||
    return password == pwdb[username]
 | 
					    return pwhash(password) == pwdb[username]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def add_user(username, pwdb):
 | 
					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
 | 
					    return pwdb
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def read_pwdb(PWDB_PATH):
 | 
					def read_pwdb(PWDB_PATH):
 | 
				
			||||||
| 
						 | 
					@ -28,6 +29,11 @@ def write_pwdb(pwdb, PWDB_PATH):
 | 
				
			||||||
    pwdb_file = open(PWDB_PATH, 'wt')
 | 
					    pwdb_file = open(PWDB_PATH, 'wt')
 | 
				
			||||||
    json.dump(pwdb, pwdb_file)
 | 
					    json.dump(pwdb, pwdb_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def pwhash(password):
 | 
				
			||||||
 | 
					    hash = ''
 | 
				
			||||||
 | 
					    for letter in password:
 | 
				
			||||||
 | 
					        hash += hex(ord(letter)**2)[2:]
 | 
				
			||||||
| 
						
							
	
 | 
				|||||||
 | 
					    return hash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    PWDB_PATH = 'pwdb.json'
 | 
					    PWDB_PATH = 'pwdb.json'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	
what's the
[2:]about?