ruano84 Posted October 18, 2006 Share Posted October 18, 2006 Hi,I am writing an user/password validator in PHP and MySQL. I am using the function crypt() to encrypt the passwords, store them in a table, and then when the users introduce their password, retrieve the stored one and compare them. This is the code to crypt and insert the password:$name="a name";$password=crypt("a password");$dbh=mysql_connect ("localhost", "user");mysql_select_db ("DataBase"); mysql_query("INSERT INTO atable (name,password) values ('$name','$password')");And this one is for retrieve it:$dbh=mysql_connect ("localhost", "user");mysql_select_db ("DataBase"); $res=mysql_query("SELECT * FROM usuarios WHERE name='a name' ");$row=mysql_fetch_row($res);$password=crypt("a password",$row[1]);if($password==$row[1]) echo "yes";if($password!=$row[1]) echo "no";For some reason, the hash of the 2nd call to the crypt function is not returning the original, so echoes "no". What could be wrong?Thanks,Alexis RR Link to comment https://forums.phpfreaks.com/topic/24382-retrieve-from-mysql-a-previously-encripted-string/ Share on other sites More sharing options...
btherl Posted October 19, 2006 Share Posted October 19, 2006 Hmm, no I am wrong. Ignore that :) I must think before typing.. Link to comment https://forums.phpfreaks.com/topic/24382-retrieve-from-mysql-a-previously-encripted-string/#findComment-111025 Share on other sites More sharing options...
redarrow Posted October 19, 2006 Share Posted October 19, 2006 why not use md5($password) just asking. Link to comment https://forums.phpfreaks.com/topic/24382-retrieve-from-mysql-a-previously-encripted-string/#findComment-111029 Share on other sites More sharing options...
btherl Posted October 19, 2006 Share Posted October 19, 2006 Are you sure that $row[1] is actually the password? Try printing out the values of $row[1], and also print out the result of that crypt() call. Link to comment https://forums.phpfreaks.com/topic/24382-retrieve-from-mysql-a-previously-encripted-string/#findComment-111034 Share on other sites More sharing options...
redarrow Posted October 19, 2006 Share Posted October 19, 2006 Heres a quick md5 example oksave as a.php[code]<?php$password="redarrow";if(isset($_POST['submit'])){if($pass==$password){echo "Hello $name <br> This is your password in md5 format ".md5($password)." ";}else{echo "Sorry $name wrong password <a href='a.php'>Try Agin</a>";exit;} }?><form method="POST" action="a.php"> <br>Your name please<br><input type="text" name="name"><br>Your password please<br><input type="password" name="pass"><br><br><input type="submit" name="submit" value="send"></form>[/code] Link to comment https://forums.phpfreaks.com/topic/24382-retrieve-from-mysql-a-previously-encripted-string/#findComment-111043 Share on other sites More sharing options...
ruano84 Posted October 19, 2006 Author Share Posted October 19, 2006 Hi, Thanks for answering,The md5() function does the same thing. I think it's a problem with MySQL, but i really don't know what's the problem.Alexis RR Link to comment https://forums.phpfreaks.com/topic/24382-retrieve-from-mysql-a-previously-encripted-string/#findComment-111183 Share on other sites More sharing options...
ruano84 Posted October 19, 2006 Author Share Posted October 19, 2006 Hi,I saw all the code and realize that there was a programming error from me. I was hashing the password 2 times inside a validation process.Thanks for everything Link to comment https://forums.phpfreaks.com/topic/24382-retrieve-from-mysql-a-previously-encripted-string/#findComment-111207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.