[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to compare in python an input value with an hashed value in mysql table?

Growth Hacking Formation <admin at formationgrowthhacking.com> writes:

> Thanks for helping. That is what I thought.
> Lets say it is the case and I get the key. We know it uses sha256 and it apply to the ascii code.
> What should be the python code in this scenario?
> I am novice and the hash python module is a bit too complex for me. I read the doc.
> Thanks.

Some of the details are still vague, but I think it must be something like this:
Here is some code that works in both Python 2 and Python 3.

import hashlib
import hmac

secretfile = '.../lmfwc-files/secret.txt' ## Fill in proper file name

with open(secretfile, 'rb') as fd:
    secret = fd.read()

key = 'goldQ3T8-1QRD-5QBI-9F22'

bkey = key.encode('ascii')

h = hmac.new(secret, bkey, hashlib.sha256)

print('hd (hex): ', h.hexdigest())

Pieter van Oostrum
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]