X次失败尝试后阻止登录 [英] blocking login after X failed attempts

查看:84
本文介绍了X次失败尝试后阻止登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在y次失败尝试后x分钟内阻止登录.我已经计划记录用户登录,所以我想我可以使用相同的数据库来计算是否需要进行阻止.

I'm trying to block login for x minutes after y failed attempts. I'm already planning to log user logins, so I guess I could use the same database to calculate if blocking needs to happen.

我的问题:

  • 使用相同的日志表运行y次失败尝试的逻辑是否有意义?
  • 有些人有一个表仅用于失败尝试,我听说他们只是增加失败登录的次数.这是没有意义的,因为它们存储的只是失败尝试的次数,而不是在什么时间段内. 10分钟内3次失败尝试与3天内3次失败尝试不同.时间跨度重要吗?您是否在y个时间间隔内阻止了x次失败尝试,周期或x次失败尝试后阻止.最好的时间表是什么?
  • 有人可以澄清这方面的最佳实践方法吗?

推荐答案

您需要所谓的密码尝试窗口".

You need what's called a Password Attempt Window.

数据库中基本上有2个字段,其中一个LastPasswordAttempt(日期时间)和PasswordAttemptCount(整数)

Basically 2 fields in the database, one LastPasswordAttempt (datetime) and PasswordAttemptCount (int)

然后在每次登录时,检查最后一次LastPasswordAttempt发生的时间以及是否在最近的10分钟内-递增PasswordAttemptCount,否则将其重置为0(或1,因为它们刚失败).

Then on each login, check when the last LastPasswordAttempt occured and if it has been in the last say 10 minutes - increment the PasswordAttemptCount, otherwise reset it to 0 (or 1 because they've just failed).

按照相同的逻辑,检查PasswordAttemptCount是否等于5或更大(如果等于)-拒绝用户访问.您可能有第三个字段,将其锁定了几个小时或一天.

In the same logic, check whether PasswordAttemptCount is equal to say 5 or more, if it is - deny the user access. You could have a 3rd field which locks them out for a few hours or a day.

即CanLoginAfter(datetime),您可以将其设置为上次尝试密码的日期.

i.e. CanLoginAfter(datetime) which you can set to a day from the last password attempt.

希望这会有所帮助

这篇关于X次失败尝试后阻止登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆