How do i get the password from the SQL database without it quoting the output?

441 Views Asked by At

My code right now is

import mysql.connector import hashlib
 
cnx = mysql.connector.connect(user='root', password='!Joshua1',
                               host='127.0.0.1',
                               database='passwordhashtest')
 
cursor = cnx.cursor()
 
Password = input("Enter the password >>")       
hashpass = hashlib.md5(Password.encode('utf8')).hexdigest()
 
Email=input("number")
 
passwordcheck='''SELECT b FROM password2 WHERE a = %s AND b = %s'''

values=(Email,hashpass)
 
cursor.execute(passwordcheck,values) 
 
hashedpassindatabase=cursor.fetchone()
 
print(hashedpassindatabase)
 
if hashedpassindatabase==hashpass:
    print("Success!") else:
    print("error")`

My output comes out as:

('d1133275ee2118be63a577af759fc052',)

error

See my problem is the quotes and the comma! HOW DO I REMOVE THAT!?!?!??!

It seems impossible, i tried everything i can think of!

hashpass is stored as

d1133275ee2118be63a577af759fc052

If the data im getting from mysql doesnt include the quotes and the comma, then things would get verified pretty easily, but it isnt. THATS WHAT I DONT GET!!!!!!!!! HELP!!!!!!!!!!!!

1

There are 1 best solutions below

2
On

The return value of a DB API2 compliant cursor.fetchone() is a sequence (or None).

In your case, the result is a tuple with a single item:

t = ('d1133275ee2118be63a577af759fc052',)

To access this item, use t[0].

Or to stick to your variable names:

hashedpassindatabase = ('d1133275ee2118be63a577af759fc052',)
actual_value = hashedpassindatabase[0]
print(actual_value)

Output:

d1133275ee2118be63a577af759fc052