Jump to content

Archived

This topic is now archived and is closed to further replies.

gardan06

regarding user passwords

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?

Share this post


Link to post
Share on other sites
store the password as md5 hash

[code]$password = md5($_GET['password']);
$sql = "INSERT INTO table_name SET password = '$password'";[/code]

Ray

Share this post


Link to post
Share on other sites
thanks ray. one more thing:

when the user logs in, how can i convert the hash back to its original password?

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
ps: There are no such things as modules in php.

Share this post


Link to post
Share on other sites
If a user logs in as [code]' OR '' = '' --[/code] they needn't bother entering a password.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.