I have a column passwd that I have encrypted with the algorithm PASSWORD(). I want to compare the password that a user has put in with
the variable that is stored in the database. I want to encrypt the value first in another variable and the compare them.
I change the column like this:
UPDATE customer SET passwd_enc=PASSWORD(passwd);
I do the login like this:
<?php
$u = $_REQUEST['username'];
$p = $_REQUEST['pass'];
$sql="SELECT * FROM customer WHERE uname=? AND passwd_enc=?";
if(! $stmt = $mysqli->prepare($sql)) {
echo "Error: " . $mysqli->error;
}else( $stmt = $mysqli->prepare($sql)) {
$stmt->bind_param("ss", $u,$p);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if($row['uname']==$u && $row['passwd_enc']==$p) {
print "Welcome $u";
$_SESSION['username'] = $u;
} else {
print "Unknown user";
$_SESSION['username'] = '?';
}
if($row['is_admin']==1){
$_SESSION['is_admin']='admin';
}else{
$_SESSION['is_admin']='user';
}
}
?>
Something like this:
$p=$_REQUEST['pass'];
$p_enc=encrypt($p);
if($p==(encrypted variable in db))
NOTE: I want the encyption to be done like the PASSWORD() function.