我想使用php重置用戶密碼。我從html表單中獲得了用戶的當前密碼和新密碼。這裏的PHP腳本來重置密碼。但即使用戶輸入正確的密碼,它也始終執行else
部分。如何?任何解決方案?我知道可能有一個簡單的錯誤,但我是新來的,無法找到任何錯誤。在php中使用密碼加密的基本錯誤
$uid = $_SESSION['uid'];
$current_pass = $_POST['org_pass'];
$new_pass = $_POST['new_pass'];
if(isset($_POST['submit']))
{
$act_pass = $db_con->prepare("SELECT password FROM user WHERE u_id= ?");
$act_pass->bindParam(1,$uid);
$act_pass->execute();
$actual_pass = $act_pass->fetchColumn();
define('SALT', 'flyingrabbit');
$typed_pass = md5(SALT.$actual_pass);
if ($typed_pass == $current_pass)
{
$new_pass1 = md5(SALT . $new_pass);
$res = $db_con->prepare("UPDATE user SET password= ? WHERE u_id=?");
$res->bindParam(1,$new_pass1);
$res->bindParam(2,$uid);
$res->execute();
header("Location: profile.php");
exit;
}
else
{
echo "<script type=\"text/javascript\">window.alert(\"You entered wrong password.\");window.location.href = 'profile.php';</script>";
}
}
你的意思是用$ actual_pass更換$ current_pass? – BetaBlaze
我想用'$ new_pass'替換'$ actual_pass'。 '$ current_pass' ..用戶以html格式輸入,這是他的密碼。 '$ actual_pass'是存儲在數據庫中的用戶密碼。 – HungryDB
您指定:if($ typed_pass == $ current_pass) 您是否100%肯定這是您想要的?在我看來,你應該這樣做: if($ typed_pass == $ actual_pass) 對於typed_pass,您將數據庫中的密碼轉換爲哈希值。你應該這樣做,而不是數據庫中的內容。 – BetaBlaze