Everyone uses bank cards. After entering the password incorrectly exceeds the limit, it is easy to be locked. Only by smartly going to the bank counter can you unlock it. So if this function is implemented, today the editor will explain it in detail through the example code. Let’s follow the editor to take a look.
Check Password implemented in C#, and lock the account according to the number of times the wrong password is entered: If the input error is 3 times, the login account will be locked for 5 minutes and prompt X minutes before trying to log in again. If you enter it again after 5 minutes, the cumulative error password will be entered to 5 times. The account will be permanently locked. You need to contact the system administrator to clear the error count in the database before logging in. The implementation code is as follows:
public class UserInfo1 { public string Error_count { get; set; } public string Error_time { get; set; } } public ExecutionResult CheckAccountPwd(string account, string password) { ExecutionResult execRes; execRes = new ExecutionResult(); string[] strs = (new string[] { "\\" }, ); if ( < 2) { = false; = "Invalid account."; } else { UserInfo1 info1 = null; execRes = (dbName, "sDEM2131", "GetUserInfo", strs[1].ToLower()); if ( && != null) { info1 = <UserInfo1>(()); if (info1 != null) { int errcount = Convert.ToInt32(info1.Error_count); DateTime errtime = (info1.Error_time); if (errcount != 5) { //int errorCount DateTime dt0 = ; DateTime dt1 = (5); double s = (dt1 - dt0).TotalSeconds; if (errcount == 3 && s > 0) { = false; = "Password input error 3 times in succession, please " + (+5).ToString("yyyy-MM-dd HH:mm:ss") + "Try again afterwards, thanks!"; } else { if (CheckFromLDAP(strs[1], password, strs[0])) { userInfo = CheckUser(strs[1]); if (userInfo == null) { = false; = "You do not have permission to operate this system!"; } else { = true; = userInfo; //error count clear 0 (dbName, "sDEM2131", "UpdateUserLoginError", strs[1].ToLower() + ","+"0" + "," + ("yyyy/MM/dd HH:mm:ss")); } } else { = false; // Number of times +1 if (errcount + 1 > 1) = "Password sequential error" + (errcount+1).ToString() + "Time. If you enter the password incorrectly for 5 consecutive times, it will be locked!"; else = "Password entry error!"; dt0 = ; (dbName, "sDEM2131", "UpdateUserLoginError", strs[1].ToLower() + "," + (errcount + 1).ToString()+"," + ("yyyy/MM/dd HH:mm:ss")); if (errcount + 1 == 3) = "Password sequential error" + (errcount + 1).ToString() + "Time, please + (5).ToString("yyyy-MM-dd HH:mm:ss") + "Try again afterwards, thanks!"; if (errcount + 1 == 5) = "The account password has been entered incorrectly for 5 consecutive times, locked! Please contact the administrator to unlock it, thanks!"; } } } else { = false; = "The account password has been entered incorrectly for 5 consecutive times, locked! Please contact the administrator to unlock it, thanks!"; } } else { = false; = "This account cannot be found, please re-enter!"; } } else { = false; = "This account cannot be found, please re-enter!"; } } return execRes; }
Form verification based on login to different domains
private bool CheckFromLDAP(string ntID, string ntPWD, string domain)//Form verification is performed according to the different domains you logged in { bool result = false; string strUser; try { strUser = domain + "\\" + ntID; if (().Equals("gi")) domain = ""; else if (().Equals("cqc_cci")) domain = "10.140.1.1"; else if (().Equals("vn")) domain = "10.144.2.101"; else if (().Equals("njp_cci")) domain = "10.128.50.1"; else domain = ""; DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain, strUser, ntPWD); using (DirectorySearcher searcher = new DirectorySearcher(entry)) { = ("(&(objectClass=user)(sAMAccountName={0}))", ntID); SearchResult sr = (); using (SearchResultCollection results = ()) { if ( > 0) { //if (results[0].("employeeID")) // empID = results[0].Properties["employeeID"][0].ToString(); //else // empID = results[0].Properties["extensionattribute3"][0].ToString(); result = true; } } } } catch (Exception ex) { //(); } return result; }
Permission management according to different user login
public bool CheckPermission(string controllerName, string actionName,string plant, string userID) { bool result = false; //if (("_")) // actionName = (1); UserInfo userInfo = CheckUser(userID); if (userInfo!=null) { if (controllerName == "Home") result = true; else if ((controllerName)) { if (!(plant)) { if (() == () || == "ALL") result = true; } else result = true; } } return result; }
Summarize
The above is the C# implementation of Check Password and lock the account lock function that I have introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!
If you think this article is helpful to you, please reprint it. Please indicate the source, thank you!