あなたができる
ユーザー
id | name | salt | password | email
password_reset_request
id | user_id | requested_on
password_reset_email
id | password_reset_request_id | email_log_id
password_reset_log
id | user_id | old_salt | old_password | reset_on
email_log
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