Jump to content

Salt + md5 Encryption


Hooo

Recommended Posts

So I have decided to use Salt + md5 encryption for passwords, and it works when the signup happens. The password is then encrypted.

 

However, I can't login with the password the user chose, I can however log in with the encrypted code, 394kj40jirji, or whatever lol.

 

Is there anything I have to use apart from:

 

$salt = 's+(_a*';
$salt_pass = md5($pword.$salt);

 

Obviously salt_pass is sent to the mysql table. That is all I have changed, what am I missing? Thanks.

Link to comment
https://forums.phpfreaks.com/topic/171222-salt-md5-encryption/
Share on other sites

Will show the two files with the hashing involved. I have done as you say, however giving me the "Wrong username" error. It won't even let me login using the actual hashs either.

 

The signup insert page:

 

<?php

include 'config.php';
include 'opendb.php';

$uname = $_POST["uname"];
$pword = $_POST["pword"];
$pword1 = $_POST["pword1"];
$jmail = $_POST["email"];
$age = $_POST["age"];
$chkname = mysql_query("SELECT * FROM Users WHERE usname='$uname'");
$salt = 's+(_a*';
$salt_pass = md5($pword.$salt);

if(mysql_num_rows($chkname) > 0 ) {
echo "Username already in use";
} else {
if ($pword != $pword1) {
echo "The two passwords do not match";
} else {

$sql="INSERT INTO Users (usname, userpass, useremail, userage)
VALUES
('$uname','$salt_pass','$jmail','$age')";

if (!mysql_query($sql))
  {
  die('Error: ' . mysql_error());
  }

?>

<html>
<body>

Registation Successful!<br /><br />
You may now <a href="index.php">login!</a>

</body>
</html>

<?php

}
}

include 'closedb.php';

?>

 

and the login check:

 

<?php

session_start();

include 'config.php';
include 'opendb.php';

$tbl_name= 'Users';

$myusername=$_POST['usname']; 
$mypassword=$_POST['userpass']; 

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$salt = 's+(_a*';
$salt_pass = md5($mypassword.$salt);

$sql="SELECT * FROM " .$tbl_name ." WHERE usname='" . $myusername. "' and userpass='".$salt_pass."'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count == 1) {
$_SESSION['usname'] = $myusername;
echo '<meta http-equiv="refresh" content="1;url=main.php">';
}
else {
echo "Wrong Username or Password";
}

include 'closedb.php';

?>

Link to comment
https://forums.phpfreaks.com/topic/171222-salt-md5-encryption/#findComment-902934
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.