gardan06 Posted August 30, 2006 Share Posted August 30, 2006 im making a simple module that will register a username and its password. what i want to happen is when the password gets saved into the database, it becomes a random character instead of the real password to avid hacking problems.how can i insert the hashed password into mysql and also, how can i call it back to its original password later? Quote Link to comment Share on other sites More sharing options...
craygo Posted August 30, 2006 Share Posted August 30, 2006 store the password as md5 hash[code]$password = md5($_GET['password']);$sql = "INSERT INTO table_name SET password = '$password'";[/code]Ray Quote Link to comment Share on other sites More sharing options...
gardan06 Posted August 30, 2006 Author Share Posted August 30, 2006 thanks ray. one more thing:when the user logs in, how can i convert the hash back to its original password? Quote Link to comment Share on other sites More sharing options...
craygo Posted August 30, 2006 Share Posted August 30, 2006 You can't. That is why you use the md5 hash. Only thing you can do is compare the passwords. If someone losses there password it can only be reset NOT retrieved.Why would you want to convert it back anyway???Ray Quote Link to comment Share on other sites More sharing options...
gardan06 Posted August 30, 2006 Author Share Posted August 30, 2006 well, i was thinking when the user logs in, the module checks if the password he typed is the same from the password in the database. i was thinking of 2 things that could compare it:1) convert the password from the database back to its original characters(which you said i cant, so maybe ill cross out this option). and:2) convert the password the user typed to md5 hash and then compare it the the md5-hashed password in the database.would option #2 be the solution or is there another way to compare the passwords? Quote Link to comment Share on other sites More sharing options...
craygo Posted August 30, 2006 Share Posted August 30, 2006 yes option 2 would be correct.[code]$username = $_POST['username']; // assign username from form to $username$password = md5($_POST['password']); //get password from form and convert it and assign to $password$sql = "SELECT * FROM table_name WHERE username = '$username' AND password = '$password'"; $res = mysql_query($sql) or die (mysql_error()); $num_rows = mysql_num_rows($res);if($num_rows >0){// continue code here} else {echo "NO SOUP FOR YOU";}[/code]Ray Quote Link to comment Share on other sites More sharing options...
gardan06 Posted August 30, 2006 Author Share Posted August 30, 2006 thanks Quote Link to comment Share on other sites More sharing options...
trq Posted August 30, 2006 Share Posted August 30, 2006 ps: There are no such things as modules in php. Quote Link to comment Share on other sites More sharing options...
Jenk Posted August 31, 2006 Share Posted August 31, 2006 If a user logs in as [code]' OR '' = '' --[/code] they needn't bother entering a password. Quote Link to comment Share on other sites More sharing options...
pmeasham Posted August 31, 2006 Share Posted August 31, 2006 [quote author=Jenk link=topic=106301.msg425213#msg425213 date=1157012227]If a user logs in as [code]' OR '' = '' --[/code] they needn't bother entering a password.[/quote]indeed, take a look at:http://uk2.php.net/manual/en/function.mysql-real-escape-string.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.