简体   繁体   English

更改密码PHP问题

[英]Change Password PHP Issue

I am running the following code below to try and update my current password in my database to the new one being specified in the form that is being to allow for password changes. 我正在下面运行以下代码,尝试将数据库中的当前密码更新为以允许更改密码的形式指定的新密码。 I am entering the same passwords in both fields so I don't understand why the error is occuring. 我在两个字段中都输入了相同的密码,所以我不明白为什么会发生错误。

      <form method='post' action="changepasswordphp.php">

        <p align="center"><strong> Complete the form to change your password </strong> </p>
            <br/>
                <label><strong>Enter Old Password:</strong></label>                 
                <input name='oldpw' type='password' required='required'/>
            <br/>
            <br/>
                <label><strong>Enter New Password:</strong></label>
                <input name='newpw' type='password' required = 'required' />  
            <br/>
            <br/>
                <label><strong>Confirm New Password:</strong></label>               
                <input name='conpw' type='password' required = 'required' />
            <br/>
            <br/>
                <input type='submit' value='Submit' class ="submit" id="submit" />          
        </form>

$mysqli = new mysqli("localhost", "root", "DBPASS", "DBNAME");
if (isset($_POST['newpw'])){
$pw=$mysqli->query("SELECT userPass FROM usertable WHERE userID= '" . $_SESSION['sess_uid'] . "'");
            $row = $pw->fetch_object();
            $pawo = $row->userPass; 

if (md5($_POST['oldpw'])== $pawo){

    if (md5($_POST['newpw'])===(md5($_POST['conpw']))){
     $mysqli->query("UPDATE usertable SET userPass='" . md5($_POST['newpw']) . "' WHERE userID='" . $_SESSION['sess_uid'] . "'");
     }
    else { echo "Passwords don't match"; }
    }

else { echo "An Error Occured";}
}

?> ?>
I am getting the error message "An Error Occured", I am unsure as to what is causing this problem. 我收到错误消息“发生错误”,我不确定是什么原因导致了此问题。 Any help would be greatly appreciated! 任何帮助将不胜感激!

Thanks 谢谢

I'm not explicitly familiar with the MySQLi code, but this looks wrong: 我不是很熟悉MySQLi代码,但这看起来是错误的:

$pw=@$mysqli->query("SELECT userPass FROM usertable WHERE userID= '" . $_SESSION['sess_uid'] . "'");
        $row = $pw->fetch_object();
        $pawo = $row->password ; 

Is the password field userPass or password ? 密码字段是userPass还是password Also, don't use MD5 (use password_hash ) and don't use == for comparing hashed passwords. 另外,请勿使用MD5(使用password_hash ),也不要使用==来比较哈希密码。 (use === instead) (改用===)

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

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