HP 文档警告我,下面的代码可能存在一些安全问题:
string storedPassword = "";
string temp;
if ((temp = ReadPassword(storedPassword)) != null) {
storedPassword = temp;
}
if(Utils.VerifyPassword(storedPassword, userPassword))
// Access protected resources
...
}如果readPassword()由于数据库错误或其他问题而无法检索存储的密码,则攻击者可以通过为userPassword提供空字符串来绕过密码检查。
好的..。我同意指示..。但是如何解决这个问题呢?代码处理密码管理的最佳实践是什么?
发布于 2018-02-27 07:03:14
您只需使用IsNullOrWhiteSpace语句:
public bool VerifyPassword(string storedPassword, string userPassword)
{
if(string.IsNullOrWhiteSpace(userPassword))
{
return false;
}
}发布于 2018-03-12 15:01:20
在有有效密码值之前,不要初始化密码(在本例中为空字符串)。
string storedPassword;
//string storedPassword = null;
string temp;
if ((temp = ReadPassword(storedPassword)) != null) {
storedPassword = temp;
}
if(Utils.VerifyPassword(storedPassword, userPassword))
// Access protected resources
...
}https://stackoverflow.com/questions/49002904
复制相似问题