Jump to content

md5 and session defining problem


solidrichard

Recommended Posts

Hi,

I my first problem is hashing passwords to md5.

My second problem is defining session on value from db.

There is my code but not working.

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$username=$_POST['username']; 
$password=$_POST['password'];
$hash = md5($password);


$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql="SELECT * FROM $tbl_name WHERE where username = '$username' and password = '$hash'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
$sql2="SELECT access FROM $tbl_name WHERE username='$username' and password='$password'";
$access=mysql_query("$sql2");
session_register("username");
session_register("password"); 
session_register("access");
$_SESSION["access"]=$access;
header("location:success.php");
}
else {
echo "Invalid Username or Password";

Thanks for any answers.

Link to comment
Share on other sites

Correct. session_register() is out dated. Use

$_SESSION['your_variable'] = $value;

instead

 

Regarding your problem, try the following:

 

$username=$_POST['username']; 
$password=$_POST['password'];
$hash = md5(stripslashes($password));

$username = stripslashes($username);
// Commented the following line. $hash is generated before the stripslahes is used
//$password = stripslashes($password);

 

This might help.

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.