密码恢复脚本不起作用


Password recovery script doesn't work

我找到了密码恢复教程,并尝试将其实施到我的当前页面中。当用户单击更改密码时,他应该输入他的电子邮件并将链接放入他的框中。到目前为止还不错。问题是当用户设置他的新密码时。它不会保存到数据库中。

这是重置的.php

    if(isset($_POST['submit']))
{
    //basic validation
    if(strlen($_POST['password']) < 3)
    {
        $error[] = 'Password is too short.';
    }
    if(strlen($_POST['passwordConfirm']) < 3)
    {
        $error[] = 'Confirm password is too short.';
    }
    if($_POST['password'] != $_POST['passwordConfirm'])
    {
        $error[] = 'Passwords do not match.';
    }
    //if no errors have been created carry on
    if(!isset($error))
    {
        try 
        {
            $stmt = $pdo->prepare("UPDATE users SET password = :password, resetComplete = 'Yes' WHERE resetToken = :token");
            $stmt->execute(array(
            ':password' => sha1($password),
            ':token' => $row['resetToken']
            ));
            //redirect to index page
            header('Location: index.php?action=resetAccount');
            exit;
            //else catch the exception and show the error.
        }
        catch(PDOException $e) 
        {
            $error[] = $e->getMessage();
        }
    }
}

形式

<form role="form" method="post" action="" autocomplete="off">
<h2>Change Password</h2>
<hr>
<div class="form-group">
<input type="password" name="password" id="password" class="form-control input-lg"   placeholder="Password" tabindex="1">
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="password" name="passwordConfirm" id="passwordConfirm" class="form-control input-lg" placeholder="Confirm Password" tabindex="1">
</div>
</div>
</div>
<hr>
<div class="row">
<div class="col-xs-6 col-md-6"><input type="submit" name="submit" value="Change Password" class="btn btn-primary btn-block btn-lg" tabindex="3"></div>
</div>
</form>

仅在密码未更改resetComplete = 'Yes'进行更新。所以我怀疑这可能是密码部分的内容。

sha1($password)您尝试将新密码作为简单变量访问。以前,您可以将其作为发布变量访问。 $_POST['password']

您应该在 sha 行之前的某处添加以下内容:

$password = $_POST['password']

或使用以下方式访问它:

sha1($_POST['password'])