So I have a password file where users passwords are stored as the MD5 hash of "changeme"..(4cb9c8a8048fd02294477fcb1a41191a)... My script, which asks for the username and password, accepts the password as plain text but I have no idea how to calculate the MD5 hash to compare it to the password file. It seems like it's too complicated to try to write an algorithm for so does anyone know of any ideas? Thanks!
# CSC 310 Project # 3
#opening passwd file
open (PSWD, '<', 'passwd.txt');
#getting username and password
#converting username to lowercase if anything is entered in CAPS
print "Please enter your username: ";
chomp($userN = <STDIN>);
$username = lc($userN);
print "Please enter your password: ";
#hiding password
system ("stty -echo");
chomp($passwd = <STDIN>);
$matchCount = 1;
#reading passwd.txt and assigning values
while ($lines = <PSWD>){
($user,$pswd,$userID,$groupID,$info,$home,$shell) = split ':', $li
+nes;
#checking username entered vs that in the passwd file
if ($username eq $user){
print "\nChecking username... MATCH\n";
#keeps track if username matches or not
$matchCount += 1;
#checking password entered vs that in the passwd file
if ($passwd eq $pswd){
print "Checking password... MATCH\n\n";
$matchCount -= 2;
}
else{
print "Password does not match!\n";
}
last;
}
}
# if matchcount did not change, username did not match killing the pro
+gram
if ($matchCount != 0){
die ("\nEither the username or password did not match.\n");
}
......
Right now, the script checks the plain text of the file (I changed the passwords stored in the password file) and works great, but the MD5 hash is going to throw me off. Any help is appreciated.