-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.py
43 lines (26 loc) · 1.05 KB
/
hash.py
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
37
38
39
from Crypto.Hash import SHA256
print ("\n\t\t____________ PASSWORD MANAGEMENT DEMO USING HASH VALUES ____________\n")
createdHash = 0
#Check the created password and validate
def passwordCreation():
userPw = input("\tCreate a new password : ")
print ("\tPassword: "+userPw)
global createdHash
createdHash = hashing(userPw)
print ("\tPassword HASH : "+createdHash)
def hashing(valueToHash): #hashing function
encodedValue = valueToHash.encode('utf-8') #Unicode text should be encoded to the bytes before hashing
tempHash = SHA256.new(encodedValue).hexdigest()
return tempHash
def checkThePassword():
print("\n\t\t_____________ DEMO PASSWORD CHECKING ____________\n")
tempPassword = input("\tEnter your password : ")
pwHash = hashing(tempPassword)
global createdHash
if (pwHash == createdHash) :
print ("\tPassword matched.")
else:
print("\tPassword mismatched.")
print ("\n\tnew hash: "+pwHash+" \n\thash in db: "+str(createdHash))
passwordCreation()
checkThePassword()