/// <summary> /// Randomizes the password. /// </summary> /// <param name="length">Specified length for password.</param> /// <returns></returns> public string RandomizePassword(int length) { EnsurePreLoad(); loginPassword = GreyFoxPassword.CreateRandomPassword(length); isSynced = false; return(loginPassword); }
/// <summary> /// Logs in a user to the system and optionally logs success and failures to the audit log. /// </summary> /// <returns>Returns associated user if one exists, or returns null if no user exists.</returns> public GreyFoxUser Login(string username, string password, string ipAddress, string clientDetails, bool logSuccess, bool logFailure) { GreyFoxUser user = null; try { user = GetByUsername(username); } catch { if (logFailure) { Amns.GreyFox.EventLog.GreyFoxEvent e = new Amns.GreyFox.EventLog.GreyFoxEvent("sysGlobal_Events"); e.Category = "Login"; e.Description = "Login failure; invalid username '" + username + "'.<BR>" + "IP Address: " + ipAddress + "<BR>" + "Client: " + clientDetails; e.EventDate = DateTime.Now; e.EventID = 25104; e.Source = "AUDITOR"; e.Type = 105; e.User = null; e.Save(); } throw(new Exception("Login failure; invalid username.")); } if (GreyFoxPassword.DecodePassword(user.loginPassword).ToLower() != password.ToLower()) { if (logFailure) { Amns.GreyFox.EventLog.GreyFoxEvent e = new Amns.GreyFox.EventLog.GreyFoxEvent("sysGlobal_Events"); e.Category = "Login"; e.Description = "Login failure; incorrect password for '" + username + "'.<BR>" + "Password used '" + password + "'.<BR>" + "IP Address: " + ipAddress + "<BR>" + "Client: " + clientDetails; e.EventDate = DateTime.Now; e.EventID = 25105; e.Source = "AUDITOR"; e.Type = 105; e.User = user; e.Save(); user.LoginCount++; user.Save(); // Delay the user 15 seconds if he's tried in the last 24 hours if (user.LoginCount == 4) { System.Threading.Thread.Sleep(15 * 1000); } // Delay the user 15 seconds + 5 second increments else if (user.LoginCount > 5 & user.LoginCount <= 11) { System.Threading.Thread.Sleep(5 * 1000 * user.LoginCount + 15 * 1000); } // Delay the user 15 seconds + 10 second increments else if (user.LoginCount > 11) { System.Threading.Thread.Sleep(15 * 1000 * user.LoginCount + 15 * 1000); } } throw(new Exception("Login failure; incorrect password.")); } if (user.isDisabled) { if (logFailure) { Amns.GreyFox.EventLog.GreyFoxEvent e = new Amns.GreyFox.EventLog.GreyFoxEvent("sysGlobal_Events"); e.Category = "Login"; e.Description = "Login failure; '" + username + "' disabled.<BR>" + "IP Address: " + ipAddress + "<BR>" + "Client: " + clientDetails; e.EventDate = DateTime.Now; e.EventID = 25110; e.Source = "AUDITOR"; e.Type = 105; e.User = user; e.Save(); } throw(new Exception("Login failure; user disabled.")); } if (logSuccess) { Amns.GreyFox.EventLog.GreyFoxEvent e = new Amns.GreyFox.EventLog.GreyFoxEvent("sysGlobal_Events"); e.Category = "Login"; e.Description = "Login success; '" + username + "'.<BR>" + "IP Address: " + ipAddress + "<BR>" + "Client: " + clientDetails; e.EventDate = DateTime.Now; e.EventID = 25001; e.Source = "AUDITOR"; e.Type = 100; e.User = user; e.Save(); // Delay the user 15 seconds if he's tried in the last 24 hours if (user.LoginCount == 4) { System.Threading.Thread.Sleep(15 * 1000); } // Delay the user 15 seconds + 5 second increments else if (user.LoginCount > 5 & user.LoginCount <= 11) { System.Threading.Thread.Sleep(5 * 1000 * user.LoginCount + 15 * 1000); } // Delay the user 15 seconds + 10 second increments else if (user.LoginCount > 11) { System.Threading.Thread.Sleep(15 * 1000 * user.LoginCount + 15 * 1000); } } user.loginCount = 1; user.loginDate = DateTime.Now; user.isSynced = false; user.Save(); return(user); }
/// <summary> /// Encrypts the currnt password. /// </summary> public void Encrypt() { this.LoginPassword = GreyFoxPassword.EncodePassword(this.LoginPassword); }
/// <summary> /// Returns a decrypted version of the password. /// </summary> /// <returns>Decoded password.</returns> public string Decrypt() { return(GreyFoxPassword.DecodePassword(this.LoginPassword)); }
/// <summary> /// Returns true if the password has been encrypted. /// </summary> /// <returns>True if password is encrypted.</returns> public bool IsEncrypted() { return(GreyFoxPassword.CheckEncryption(this.LoginPassword)); }