c# - 设置用户登录尝试时出现逻辑错误

标签 c# asp.net authentication passwords

我的 asp.net 应用程序使用自定义逻辑来实现用户登录功能。要求之一是用户(一旦锁定)必须在 15 分钟后才能获得访问权限。

我目前的逻辑是:

// check if account is locked & LastLoginAttempt is NOT over 15 minutes;
if ((iLoginAttempts > 4) && ( dtCurrentTimePlus15 < dtLastLoginAttempt))
{
    oCust.CustLoginStatus = "Your account is currently locked.";
    return false;
}  

但是,当 iLoginAttempts = 5 且 dtLastLoginAttempt 是 2 分钟前时......为什么上面的逻辑会跳过 if 子句?

最佳答案

因为

 dtCurrentTimePlus15 = 15

dtLastLoginAttempt = 2

将语句反转为:

if ((iLoginAttempts > 4) && (dtLastLoginAttempt < dtCurrentTimePlus15))
{
    oCust.CustLoginStatus = "Your account is currently locked.";
    return false;
}  

关于c# - 设置用户登录尝试时出现逻辑错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11723770/

相关文章:

c# - WinForms 应用程序的 Windows 窗体身份验证

docker - 使用 docker、ansible 和身份验证部署的 Elasticsearch 集群

ios - 在 parse.com 的 ios 中使用 google plus 登录

c# - 当前上下文中不存在名称 'ConfigurationManager'

c# - 安装 log4net 多个项目

c# - 无法打开 VS 2019 中当前不可用的终端窗口?

c# - 如何在服务器标记的 aspx 文件中调用代码隐藏函数

c# - 请求中的重定向 URI : http://localhost:12349/authorize/did not match a registered redirect URI

c# - C# 中的 SHA1 哈希是否会永远为给定字符串返回相同的值?

asp.net - 输出缓存与应用程序缓存?