Reputation: 27
I am just testing out md5 hashing in python 3.4.3. And i dont understand the results i am getting. I am trying to compare a hashed password in my sql database, but every other time i try to do it i get a different result. Here is a code i created to illustrate my problem:
import hashlib
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
p = '5'
for i in x:
k = hashlib.md5(p.encode('utf-8'))
print(k)
Results:
<md5 HASH object @ 0x02A07B10>
<md5 HASH object @ 0x02A07CF0>
<md5 HASH object @ 0x02A07B10>
<md5 HASH object @ 0x02A07CF0>
<md5 HASH object @ 0x02A07B10>
<md5 HASH object @ 0x02A07CF0>
<md5 HASH object @ 0x02A07B10>
<md5 HASH object @ 0x02A07CF0>
<md5 HASH object @ 0x02A07B10>
<md5 HASH object @ 0x02A07CF0>
<md5 HASH object @ 0x02A07B10>
Upvotes: 0
Views: 1185
Reputation: 17329
Your output is printing the addresses of the HASH
object, not the MD5 digest itself.
If you want to see that, then call digest()
on that object. That will return the 128-bit output of MD5 as a 16-byte string. If you want to print it out in Hexadecimal, use hexdigest()
instead:
k = hashlib.md5(p.encode('utf-8')).hexdigest()
Upvotes: 4