用户在重置密码时不应使用以前的密码?

user should not use previous password when reset passwod?

我有一个网站,我想限制用户在重置密码时不能使用前3个密码作为新密码。

将以前的散列密码保存在数据库中,并在创建新密码时检查它是否与以前的密码不匹配。

将他们以前的密码存储在数据库中。 old_pass_1、old_pass_2 和 old_pass_3。

submits password for update
check if new password matches with any of the field old_pass_1, old_pass_2 or old_pass_3. If not then proceed else go to %
check if old_pass_1 is empty - store old pass here and go to #
else check if old_pass_2 is empty - yes - move old_pass_1 to old_pass_2 and update old_pass_1 with old password and go to #
else check if old_pass_3 is empty - yes - move old_pass_2 to old_pass_3 and old_pass_1 to old_pass_2 and store the old pass to old_pass_1
else if none of them is empty then move move old_pass_2 to old_pass_3 and old_pass_1 to old_pass_2 and store the old pass to old_pass_1
# store the new password to the password field.
%Display message password was already used earlier by you.

您已将所有三个密码存储在 table 中,如 old_password、old_password1、old_password2。 当用户请求更改密码时,从 table 中获取所有三个密码 如果当前密码与最后三个密码不相等,则比较它们然后更新。 我更喜欢使用 switch case 而不是 if else log。

$a='old_password1';
$b='old_password2';
$c='old_password3';
$pass ='new password ';
switch ($pass){
    case $a:
        echo "nope1";
        break;
     case $b:
        echo "nope2";
        break;
     case $c:
        echo "nope3";
        break;
    default :
        echo "update password here";
}

性能明智的 switch case 比其他许多 if 链要好。
希望它能帮助你。编码愉快。