我得到了一些其他开发人员的代码,他们创建了一些登录安全策略.例如,如果您尝试使用数据库中存在的用户名登录,它将开始记录失败的登录尝试次数.然后在达到3次登录尝试后,它会在日志中添加另一个条目,但将第1位添加到LockedOut.
你们相信这是一个很好的安全政策吗?尝试获取条目的人不会尝试大量随机用户名并强行锁定所有人的帐户吗?对于安全而言,这似乎是一种糟糕的哲学.
我认为更好的安全程序是锁定任何根据跟踪各种用户尝试的IP表进行3次尝试的人,并在30分钟左右到期以防止DDoS.
你们是如何设计登录安全性的?这是开发人员基本上做的:
if username is in database:
if first login: increase fail-attempt counter.
if second login: lock out username.
else: don't let him in.
else:
incorrect password.
Run Code Online (Sandbox Code Playgroud)
编辑:最终程序:
public void ResolveTimeouts()
{
if (data.Expire <= DateTime.Now)
{ // it will only delete ONE single entry from the database,
// that happens to be this user's IP
// If and only if, The expiration date is older than right now.
Delete(this.data);
data.Attempts = 0;
}
}
int uid = UserExists(username);
if(uid < 1){
ResolveTimeOuts(); // this will delete IPs from table if expiration passed
if(loginAttempts >= 3){
"Fail login, you have been locked out for " + TIMEOUT + " minutes";
ExtendExpiration(TIMEOUT);
} else {
IncrementAttempts();
"fail login, incorrect username or password.";
}
} else {
if(authenticate(uid, password)){
"Successfully logged in.";
} else {
// INSERT lock out specific username feature here.
"failed login, incorrect username or password.";
}
}
Run Code Online (Sandbox Code Playgroud)
我不同意。我觉得完全锁定用户名更安全(不考虑IP)。
当恶意黑客伪造 IP 地址时会发生什么?黑客可以随意更改 IP 地址并不断暴力破解用户名。
尝试 3 次后,我锁定了 15 分钟。
对您的编辑的评论:
我会做这样的事情:
if(resolveTimeOuts()){
bool uid = UserExists();
//do other stuff
}else{
"Your IP has been locked. Enter this code to prove you are human."
// Captcha or math equation.
}
Run Code Online (Sandbox Code Playgroud)
不过,我不会删除resolveTimeOuts(). 它可以增加函数的执行时间。做这样的事情:
if(resolveTimeOut()){
bool uid = UserExists();
//do other stuff
}else{
"Your IP has been locked. Enter this code to prove you are human."
if(rand(1,5) == 5){
// or something equivalent
deleteExpiredRequests();
}
// Captcha or math equation.
}
Run Code Online (Sandbox Code Playgroud)
这将提供快速执行,resolveTimeOut()并且如果 IP 请求太快,则所有过期的超时都将被删除。这对 DoS 黑客来说是双重打击。deleteExpiredRequests()他们获得不同的页面,如果存在大量过期页面,页面的生成可能会减慢。
编辑二:这或多或少是我会实现的。我会编写完整的代码,但我用 PHP 编程。
bool function humanRequest(){
// decide if the request lag is humanistic or bot speed
// for example: last_request > this_request - 500;
}
if(!humanRequest()){
// redirect to a Captcha page or die with a warning or something (like SO does)
}
uid = getUsername(username);
if(uid > 0){
// validated request
}
else{
// increase attempts
// you could have a separate column for IP requests or whatever
// lock out username after 3 attempts
}
Run Code Online (Sandbox Code Playgroud)
您可以将其放在humanRequest()用户名验证的两种情况中。基本上,如果他们在短时间内请求任何用户名,请将其列入黑名单。但是,如果您在特殊页面中验证用户名(仅当有人尝试登录时才会包含该页面),这已经解决了这个问题。
这样,您只需要添加另一个表即可。无需修改您拥有的表。
| 归档时间: |
|
| 查看次数: |
1418 次 |
| 最近记录: |