Jump to content

passwords


leequalls

Recommended Posts

I have tried finding an answer to this but was not successful. I need a script where when a user registers the password they set up is encrypted into the mysql database I know I need to use md5 and it is 32 characters long. How would the script unencrypt it when the user tries to login?

 

Thanks

For any help

Link to comment
https://forums.phpfreaks.com/topic/163142-passwords/
Share on other sites

You don't decrypt the md5'd password instead you md5 the password the user provides upon login and then compare that to the md5 password in your database that corresponds to the username they used.

 

Example code

if(isset($_POST['username'], $_POST['password']))
{
    $user = mysql_real_escape_string($_POST['username']);
    $pass = md5($_POST['password']);

    $sql = "SELECT * FROM members WHERE username='$user' AND password='$pass'";
    $result = mysql_result($sql);

    if(mysql_num_rows($result) == 1)
    {
         // user passes login
    }
    else
    {
         // user fails login
    }
}

Link to comment
https://forums.phpfreaks.com/topic/163142-passwords/#findComment-860716
Share on other sites

I am having a problem I dont know what is wrong I have setup the md5 encryption to be saved into the database to be 4ff9018a647ae315a7e6601a818b4940 but when I do the login the md5 output is not the same for the same password login output ad0234829205b9033196ba818f7a872b

 

the password i used was test2

Link to comment
https://forums.phpfreaks.com/topic/163142-passwords/#findComment-860752
Share on other sites

registration code

 

if ($_GET['reg'] == 'y') {
if ($_POST['form'] == 'sent') {
$name = safe($_POST['name']);
$username = safe($_POST['username']);
$email = safe($_POST['email']);
$passwrd = safe(md5($_POST['passwrd']));
$datetime = $_POST['date'];
$ip = safe($_POST['ipaddr']);

$new_ins = "insert into $who (name, username, email, passwrd, lastaccess, ip_address) values ('$name', '$username', '$email', '$passwrd', '$datetime', '$ip')";
$res = mysql_query($new_ins) or die (mysql_error());
echo("

<div id=main>
<center>
You'r Registration has been sent to the admin and will be reviewed for activation.<p> Thank You<br>

");

}

 

 

Login Code

 

$username = safe($_POST['username']);
$passwrd = safe(md5($_POST['passwrd']));
$res = mysql_query("select count(*) from $who where username='$username'");
if (mysql_result($res, 0) >= 1) {
$dbdj = mysql_query("select * from $who where username='$username'");
$dbpass = safe(md5(mysql_result($dbdj, 0, 'passwrd')));
$dbactive = mysql_result($dbdj, 0, 'active');
if ($passwrd != $dbpass) {

Link to comment
https://forums.phpfreaks.com/topic/163142-passwords/#findComment-860766
Share on other sites

u are using md5 when fetching the password from the database

 

change it to this:

$dbpass = mysql_result($dbdj, 0, 'passwrd');

 

and remove the safe() fromt the $_POST:

$passwrd = md5($_POST['passwrd']);

 

since the password in the database is alreadry hashed u don't need to hash it again just hash the $_POST password and compare it with the one in the database

Link to comment
https://forums.phpfreaks.com/topic/163142-passwords/#findComment-860796
Share on other sites

u are using md5 when fetching the password from the database

 

change it to this:

$dbpass = mysql_result($dbdj, 0, 'passwrd');

 

and remove the safe() fromt the $_POST:

$passwrd = md5($_POST['passwrd']);

 

since the password in the database is alreadry hashed u don't need to hash it again just hash the $_POST password and compare it with the one in the database

Yeah, this is a common mistake for newer programmers. See if it works now.

Link to comment
https://forums.phpfreaks.com/topic/163142-passwords/#findComment-860804
Share on other sites

Archived

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

×
×
  • 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.