您可以使用ASP.NET 成员资格提供程序,如果您使用的是 SQL-Server,则可以从SqlMembershipProvider
.
然后你可以覆盖ValidateUser
并记录它是否返回false
(或总是)。
bool isValid = base.ValidateUser(username, password);
您可以通过以下方式获取ip:
public static void logWrongPasswordAttempt(string userName, string passWord)
{
// Look for a proxy address first
var IP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
//Trim and lowercase IP if not null
if ((IP != null))
{
IP = IP.ToLower().Trim();
}
if (IP == null || IP.Equals("unknown"))
{
//If IP is null use different detection method else pull the correct IP from list.
IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToLower().Trim();
}
List<string> IPs = null;
if (IP.IndexOf(",") > -1)
{
IPs = IP.Split(new[]{','}, StringSplitOptions.None).ToList();
}
else
{
IPs = new List<String>() { IP };
}
foreach (string ip in IPs)
{
// insert your record into database
}
}