I'm using python 3 and i need to know how to use hashing in python 3 on a variable instead of a string.
my example; this is the code i'm currently trying to use and it doesn't work.
foundpassencypt = hashlib.md5(b(pwd))
print(foundpassencypt.hexdigest())
pwd is a string that was entered earlier in my program.
pwd = "Password"
i know if it was a string it would be layed out like this;
foundpassencypt = hashlib.md5(b"Password")
print(foundpassencypt.hexdigest())
This is the full code (its using Python3, SQL Lite and Appjar)("Else:" is out of place when i post the code, its correct in my code)
else:
usr = login.getEntry("Username")
pwd = login.getEntry("Password") #collects entry of password & username
conn = sqlite3.connect("uHubDatabase.db")
cursor = conn.cursor() #connects to database
find_user=("SELECT Username FROM UserTable WHERE Username = ?") #sets the finding of the username from the database as a varaible
cursor.execute(find_user,[(usr)])
founduser = str(cursor.fetchall())
print(founduser)
removechars = "'(),[]" #Avoids the error of special characters caused by the database outputting strings (Text)
for char in removechars:
founduser = founduser.replace(char,'')
find_pass=("SELECT Password FROM UserTable WHERE Password = ?") #sets the finding of the password from the database as a varaible
cursor.execute(find_pass,[(pwd)])
foundpass = str(cursor.fetchall())
print(foundpass)
removechars = "'(),[]" #Avoids the error of special characters caused by the database outputting strings (Text)
for char in removechars:
foundpass = foundpass.replace(char,'')
pwdencypt = hashlib.md5(pwd) #makes the encypted password using md5 hashing
print(pwdencypt.hexdigest()) # checks the string for comparison
print(founduser)
print(usr)
print(foundpass)
print(pwd)
if founduser == usr and foundpass == pwdencypt: # If correct
print("SUCESS")
login.stop()
home.go()
else: #if incorrect
print("FAIL")
login.retryBox("INCORRECT LOGIN", "The Username or Password entered are incorrect. Please try again.", parent=login)
print("User:", usr, "Pass:", pwd)
conn.close() #closes connection