-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstspwd.py
More file actions
36 lines (25 loc) · 961 Bytes
/
stspwd.py
File metadata and controls
36 lines (25 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/python3
# secures user password to store it in database
# uses sha512
# import modules
import getpass
import hashlib
import uuid
# secure the password
def hashpwd(f_password):
uuid_2ba = uuid.uuid4().hex # generate a random hex UUID
p_pwd = hashlib.sha512(uuid_2ba.encode() + f_password.encode()).hexdigest() + ':' + uuid_2ba
return p_pwd
# check successive inputs
def checkpwd(hashed_password, c_password):
genF_part, uuid_2ba = hashed_password.split(':')
return genF_part == hashlib.sha512(uuid_2ba.encode() + c_password.encode()).hexdigest()
while True:
f_password = getpass.getpass(prompt='Please enter your password: ')
hashed_pwd = hashpwd(f_password)
crnt_pwd = getpass.getpass(prompt='Enter the password again: ')
if checkpwd(hashed_pwd, crnt_pwd):
print('Successful entry, congratulations!\n')
break
else:
print("Passwords don't match. Try again...")