简体   繁体   English

我无法使用sha1更新mysql数据库中的密码(php忘记了密码系统)

[英]I can't update password in mysql database with sha1 (php forgot password system)

First of all I'm very new to PHP so don't be to hard on me. 首先,我对PHP还是很陌生,所以请不要对我施加压力。 I'm trying to make a forgot password system for my website, but I can't update the password in the mysql database with sha1. 我正在尝试为我的网站创建一个忘记密码的系统,但是无法使用sha1更新mysql数据库中的密码。 If I do it before sha1 encrypting it works(commented out query in the code) 如果我在sha1加密之前执行了此操作(代码中的注释已注释掉)

What I want is to receive a random password on the users mail, but in the database I want it to be encrypted with sha1. 我想要的是在用户邮件上接收随机密码,但是在数据库中,我希望使用sha1对其进行加密。

Could really use some help here. 真的可以在这里使用一些帮助。

<?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);

?>
  <form name="form" action="" method="post">
  <input type="text" name="email"  value="">
  <input type="submit" name="update password" />
  </form 

check the form method in the first then remove the single qoute in this line of code to be as shwon 首先检查表单方法,然后删除此代码行中的单个qoute

$con->query("UPDATE bruker SET passord = '$passwordE' WHERE ePost='$email' ");

Note: the mail function will not work on the localhost 注意:邮件功能在本地主机上不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM