首先,我对PHP非常陌生,所以不要对我不好。我试图为我的网站制作一个忘记密码系统,但我无法使用sha1更新mysql数据库中的密码。如果我在sha1加密之前这样做它可以工作(在代码中注释掉了查询)
我想要的是在用户邮件上接收随机密码,但在数据库中我希望用sha1加密。
真的可以在这里使用一些帮助。
<?php
include("connect.php");
if(isset($_POST["email"])) {
$email = $con->real_escape_string($_POST["email"]);
$data = $con->query("SELECT * FROM bruker WHERE ePost='$email'");
if ($data->num_rows > 0) {
$str = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
$str = str_shuffle($str);
$str = substr($str, 0, 15);
$passwordD = $str;
//$con->query("UPDATE bruker SET passord = '$passwordD' WHERE ePost='$email'");
echo $passwordD;
$url = "http://localhost/example";
$msg = "Your new password is: $passwordD\nTo change your password, please visit this: $url";
$subject = "Reset Password";
$headers = "From: Vikerfjell" . "\r\n";
mail($email, $subject, $msg, $headers);
$salt = 'IT2_2017';
$passwordE = sha1($salt.$passwordD);
echo $passwordE;
$con->query("UPDATE bruker SET passord = '$passwordE' WHERE ePost='$email''");
} else {
echo "Please check your link:";
}
} else {
header("Location: index.php");
}
mysqli_close($con);
?>
答案 0 :(得分:0)
<form name="form" action="" method="post">
<input type="text" name="email" value="">
<input type="submit" name="update password" />
</form
首先检查表单方法,然后删除此行代码中的单个qoute,作为shwon
$con->query("UPDATE bruker SET passord = '$passwordE' WHERE ePost='$email' ");
注意:邮件功能不适用于localhost