im trying to hash a password from a file and then match it with the password given by the user. it's not ment to be super safe just safe enought so that the password isn't plain text in the file. I get the error
TypeError: Unicode-objects must be encoded before hashing
it works if i type hashpass = hashlib.md5(b'p').hexdigest() but then it only encrypts "p"
How do i get it to encrypt my string inputs?
PROGRAM
import hashlib
status = ""
def passhash():
code = open("password.txt", "r")
password = code.readline()
global encrypt
encrypt = hashlib.md5(password).hexdigest()
def checkPassword():
for key in range(3):
p = input("Enter the password >>")
hashpass = hashlib.md5(p).hexdigest()
if hashpass == encrypt:
print("password correct!")
status = "q"
return status
else:
print ('wrong password, try again')
print ('you have failed')
def Main():
status = input("p for program, q to quit: ")
if status == "p":
passhash()
checkPassword()
elif status == "q":
print("Byebye")
status = "q"
return status
while status != "q":
status = Main()}