-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhash_password.py
More file actions
24 lines (17 loc) · 798 Bytes
/
hash_password.py
File metadata and controls
24 lines (17 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import hashlib
import uuid
def hash_password(password):
salt = uuid.uuid4().hex
return hashlib.sha256(salt.encode() + password.encode()).hexdigest() + ':' + salt
def check_password(hashed_password, user_password):
password, salt = hashed_password.split(':')
return password == hashlib.sha256(salt.encode() + user_password.encode()).hexdigest()
if __name__ == '__main__':
password = input('Please enter a password:')
hashed_password = hash_password(password)
print('The string to store in the db is:{}'.format(hashed_password))
password_again = input('Now please enter the password again to check: ')
if check_password(hashed_password, password_again):
print('You entered the right password')
else:
print('The password does not match')