Python md5 password value

I have this password change request form. In which the user enters their old passwords.

this old password is md5 format.

How to compare md5 value from db with old password entered by user

 import md5

 oldpasswd_byuser=str("tom")
 oldpasswd_db="sha1$c60da$1835a9c3ccb1cc436ccaa577679b5d0321234c6f"
 opw=     md5.new(oldpasswd_byuser)
 #opw=     md5.new(oldpasswd_byuser).hexdigest()
 if(opw ==      oldpasswd_db):
    print "same password"
 else:
     print "Invalid password" 
+3
source share
4 answers

the hash you set is the salty sha1 hexdigest, since django (and probably many others) keeps it by default.

code to verify that it is in contrib / auth / models.py . From there, you can see that django works with md5 by default. All you have to do is update the old hashes to the following form:

md5$<salt>$<hash>

, (md5$$<hash>), sha1 , .

+3

, oldpasswd_db MD5. - (SHA1 ), .

:

import hashlib
hashlib.sha1('c60datom').hexdigest()
+2

md5, sha1 - "sha1$xxx.

sha1. http://docs.python.org/library/sha.html

+1

, , :

import md5

input_password = request.POST['password']
md5_hashed_input_password = md5.new(input_password).hexdigest()
#comapre the value to that stored in db
if md5_hashed_input_password == db_password:  #password in db should be stored in md5 hash format
    print 'password match'
else:
    print 'password mismatch'
0

Source: https://habr.com/ru/post/1771253/


All Articles