The name in your form is user_name
, but in your script you are looking for username
$username=$_POST['username'];
it should be
$username=$_POST['user_name'];
EDIT:
If you use crypt to encrypt your password before putting it into the database, try
$sql="SELECT * FROM $tbl_name WHERE username='$username'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ $row = mysql_fetch_assoc($result); if (crypt($password, $row['password']) == $row['password']){ session_register("username"); session_register("password"); echo "Login Successful"; return true; } else { echo "Wrong Username or Password"; return false; } } else{ echo "Wrong Username or Password"; return false; }
EDIT: myBB seems to use md5 hash crapload for its passwords, try this
$sql="SELECT * FROM $tbl_name WHERE username='$username'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ $row = mysql_fetch_assoc($result); if (md5(md5($row['salt']).md5($password)) == $row['password']){ session_register("username"); session_register("password"); echo "Login Successful"; return true; } else { echo "Wrong Username or Password"; return false; } } else{ echo "Wrong Username or Password"; return false; }
Also hashing is one of the ways, so you cannot return passwords already in db, you just need to force users to change / update their passwords.
If this works, you do not have to turn off encryption, and everything should be fine.
source share