我有pwd_history包含 id(PK)、old_password、created_date、user_id 列的表。当用户修改密码时,将向该表添加额外的行。我想要一个查询,通过该查询,它应该验证输入的密码是否在用户修改的最后三个密码中。Mysql 中有办法吗?谢谢。
如果密码是使用 mysql 的默认password
进行哈希处理的,则
尝试此操作,使用有效的输入值:
更新:
select * from (
select * from old_pwds_table
where user_id=input_id
order by created_date desc
limit 3
) a
where
old_password=password('new password')
前一个答案:
select * from old_pwds_table
where user_id=input_id
and old_password=password('new password')
order by created_date desc
limit 3
检查此函数希望对您有所帮助:
function check_old_pass($new_pwd){
$result=mysql_num_rows(mysql_query("select * from old_pwds_table
where user_id=input_id
and old_password=$new_pwd
order by created_date desc
limit 0,3"));
if ($result==1) {
return true;
} else {
return false;
}
}
SELECT
*
FROM
pwd_history
WHERE
user_id = 'USER_ID'
AND
oldpasswords = 'NEW_PASSWORD'
ORDER BY
created_date DESC
LIMIT 3