/// <summary> /// Creates a new user account in the database. /// This new account becomes the currently active account. /// </summary> /// <param name="name"></param> /// <param name="password"></param> /// <param name="passwordProtected"></param> public static void CreateNewAccount(string name, string password) { LoadAccountFromDB(name); EMMADataSet.UserAccountsRow account = userData.FindByName(name); if (account == null) { EMMADataSet.UserAccountsRow newUser = userData.NewUserAccountsRow(); newUser.Name = name; Password pwd = new Password(password); newUser.Password = pwd.GetSaltedHash(); newUser.Salt = pwd.Salt; newUser.Tries = 0; newUser.Locked = false; newUser.LastReportGroup = 0; userData.AddUserAccountsRow(newUser); try { userAccountsTableAdapter.Update(userData); userData.AcceptChanges(); } catch (Exception ex) { throw new EMMADataException(ExceptionSeverity.Critical, "Unable to create new account.", ex); } } else { throw new EMMAException(ExceptionSeverity.Error, "Account '" + name + "' already exists."); } }
/// <summary> /// Open a user account. /// If the account does not have a password protection flag then the user is allowed access /// regardless of the value of the password paramters, otherwise, the password is encrypted /// and this must match the encrypted password stored in the database. /// </summary> /// <param name="name">The name of the account to open</param> /// <param name="password">The password to open the account</param> public static void OpenAccount(string name, string password) { Diagnostics.StartTimer("OpenAccount.LoadAccount"); LoadAccountFromDB(name); EMMADataSet.UserAccountsRow account = userData.FindByName(name); Diagnostics.StopTimer("OpenAccount.LoadAccount"); if (account != null) { Password pwd = new Password(password, account.Salt); if (!account.Locked) { if (account.Password.Trim().Equals(pwd.GetSaltedHash())) { _name = account.Name.Trim(); Diagnostics.StartTimer("OpenAccount.InitSettings"); InitSettings(); // Set API base URL EveAPI.URL_EveApiHTTPS = _settings.APIURL; Diagnostics.StopTimer("OpenAccount.InitSettings"); Diagnostics.StartTimer("OpenAccount.GetGroups"); _reportGroups = ReportGroups.GetUsersGroups(_name, true); Diagnostics.StopTimer("OpenAccount.GetGroups"); // Automatically set the current report group to the last one used. for (int i = 0; i < _reportGroups.Count; i++) { ReportGroup group = _reportGroups[i]; if (group.ID == account.LastReportGroup) { CurrentGroup = group; i = _reportGroups.Count; } } } else { account.Tries = account.Tries + 1; /*if (account.Tries > 3) { account.Locked = true; }*/ userAccountsTableAdapter.Update(account); throw new EMMAInvalidPasswordException(ExceptionSeverity.Warning, "Incorrect password entered for account '" + name + "'"); } } else { throw new EMMAException(ExceptionSeverity.Error, "This account is currently locked. Please contact an administrator."); } } else { throw new EMMAException(ExceptionSeverity.Error, "Cannot find account '" + name + "'"); } }