Jump to content

regarding user passwords


gardan06

Recommended Posts

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?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.