Comparing MD5s in Python -
For a programming drill I created for myself, and later for use in a pretty non-secure system , I'm trying to compare MD5 hash to the one that is stored in a plain text file and it is extracted by the check_pw ()
function and submitted from a CGI form The password created with md5_pw (
) is created to create all the hash in the program A is used.
For any reason, if (pair [1] == md5_pw (pw))
always fails , although my program prints the same hashes in my error checking lines:
print "PW is from the file:", pair [1], "& Br> & gt; Print "This is the MD5 PW you have entered:", MD5_p.view. (PW), "
"
Where am I messing up?
Code:
def md5_pw (PW): "" PD's MD5 returns to hex digest. " "M = MD5. NUU () M. UPDATE (" 4 HJ 2Vic 7Q DHD 9 SDFFF 9 "+ PW) Returns M. HexDogest () Def Check_PW (User, PW, Pwfile):" Return "if user is correct Name and password match, wrong otherwise Pwfile is a xxx.txt format. "F = open in the pwfile line f: pair = line.split (": ") Print" This file is PW: ", pair [ 1], "& lt; Br / & gt; "print" This is the MD5 PW you have entered: ", MD5_PP.VW (PW)," & lt; Br / & gt; "if (pair [0] == user): print" user matched & lt; "If (pair [1] == md5_pw (pw)): f.close () return true: f.close () print" passmatch a failure "returned incorrect
Your pair [1]
Perhaps a previous new line is try:
for line f: line = line.rstrip () pair = line.split (":") # ... etc
Comments
Post a Comment