-1

I have been using the following code to convert a string into an md5 hash:

password = passwd.hexdigest()

passwd is supposed to be 'test123' so it is supposedly turning that into an md5 hash.

It gives me the following:

6adf97f83acf6453d4a6a4b1070f3754

Now when you decrypt that hash, it does not go back to 'test123'.

This is the correct md5 hash that goes back to 'test123':

cc03e747a6afbbcbf8be7668acfebee5

This is the code:

passw = request.forms.get('password')
password = hashlib.md5(str(passw)).hexdigest()

How can I work this out so it gives me the correct reversable hash?

1 Answers1

3

6adf97f83acf6453d4a6a4b1070f3754 is actually md5 value of "None", so maybe you get something wrong elsewhere.

Let's say you didn't actually get the passw from request.forms, and parse the None to str(), then gives it to md5().hexdigest(), you'll just get the result.

Felix Yan
  • 14,841
  • 7
  • 48
  • 61
  • 1
    @JasonDecastro You could just try to log or print the result of ``request.forms.get('password')``, and if you passed something to ``password`` and get a ``None``, you get problem at this part - and that's a different question than "hashlib md5 doesn't actually turn into md5?" – Felix Yan Aug 21 '13 at 07:06
  • 2
    @JasonDecastro the code you've posted implies there is no `password` field being sent... try changing to `request.forms['password']` and handling any `KeyError` instead... – Jon Clements Aug 21 '13 at 07:06
  • It was returning None. I fixed the problem. Thanks! – Jason Decastro Aug 21 '13 at 07:16