我真的很擅长数据库设计,如果你能提供一些关于如何构建用于保存密码重置日志的表的指导,我真的很赞赏。 搜索了一下,我发现了这个:
table user
-------------
id integer primary key auto_increment
username varchar
salt_passhash varchar
......
table tokenreset
---------------
id integer primary key auto_increment
user_id integer
when_requested timestamp
all_done boolean default false
但我仍然不确定这两张桌子是否足够,让我们说如果我想知道:
密码何时重置?
电子邮件何时发送?
用户请求重置密码等的次数
我应该把所有这些字段都放在tokenreset
表???
非常欢迎任何建议或想法
答案 0 :(得分:2)
你可以做到
用户
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
答案 1 :(得分:0)
你好两张桌子
表1
用户名
密码
EMAILID
状态表2
USER_ID
时间戳
hashid
....
每当用户请求密码重置时,将状态设置为1 并且您可以计算table2中具有用户ID的行数以获取请求数 和最新的密码重置查询按时间戳