你可以做
用户
id | name | salt | password | email
密码重置请求
id | user_id | requested_on
密码重置电子邮件
id | password_reset_request_id | email_log_id
密码重置日志
id | user_id | old_salt | old_password | reset_on
电子邮件日志
id | address_to | address_from | body
这也将允许您实现诸如“在 m 天 / n 次更改内不能使用相同的密码”之类的事情。
供评论:这可能在用户定义的函数中实现为
create function dbo.ValidatePassword
( @user_id int, @new_password varchar(100) )
returns bit
as
begin
declare @now datetime = getdate()
declare @i int
-- check password not repeated within the last 90 days
select @i = case when not exists(
select 1
from password_reset_log
where user_id = @user_id
and datediff(d, reset_on, @now) > 90
and old_password = HASHBYTES('SHA1', old_salt+@new_password)
)
then 1 else 0 end
-- check the password has been changed 5 times or more since it was last used
select @i = case when ( select count(1)
from password_reset_log
join (select user_id, MAX(reset_on) reset_on
from password_reset_log
where user_id = @user_id
and old_password = HASHBYTES('SHA1', old_salt+@new_password)
group by user_id
) last_used
on last_used.user_id = password_reset_log.user_id
and last_used.reset_on < password_reset_log.reset_on ) >= 5
then 1 else 0 end * @i
return @i
end