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