public Result UpdateAccount(Account account, bool deleteAccount) { IList<Account> accounts = GetAccounts().ToList(); var result = new Result() { Activity = deleteAccount ? "Delete Account" : "Update Account" }; if (accounts.Count > 0 && accounts.All(x => x != null)) { if (deleteAccount) { accounts.Remove(accounts.FirstOrDefault(x => x.UserName == account.UserName)); } else { accounts.Remove(accounts.FirstOrDefault(x => x.UserName == account.UserName)); accounts.Add(account); result.Account = account; } using (TextWriter writer = new StreamWriter(_FileName)) { _Serializer.Serialize(writer, accounts.ToArray()); } result.IsSuccessful = true; } else { result.IsSuccessful = false; result.Reason = "Xml did not return any accounts."; } return result; }
public Result UpdateAccount(Account account, bool deleteAccount) { Debug.Assert(_XmlAccountStore.Value != null && _XmlAccountStore.IsValueCreated); Debug.Assert(account != null); lock (_SyncObject) { return _XmlAccountStore.Value.UpdateAccount(account, deleteAccount); } }
public Result CreateAccount(Account account) { IList<Account> accounts = GetAccounts().ToList(); accounts.Add(account); using (TextWriter writer = new StreamWriter(_FileName)) { _Serializer.Serialize(writer, accounts.ToArray()); } return new Result() { Activity = "Create Account", Account = account, IsSuccessful = true, }; }
public Result CreateAccount(string userName, string password, string firstName, string lastName, UserSecurityLevel level = UserSecurityLevel.Standard) { var isAcceptableAccount = _UserAccountEngine.Value.ValidateNewUserAccount(userName, password); if (!isAcceptableAccount.IsSuccessful) return isAcceptableAccount; var account = new Account() { UserName = userName, FirstName = firstName, LastName = lastName, IsLocked = false, LoginAttempts = 0, Password = new List<string>() { password }, PasswordLastChangedDate = DateTime.Now, UserSecurityLevel = level }; return _UserAccountAccessor.Value.CreateAccount(account); }
private Result Login(Account account, string password) { Result result; if (account.Password.LastOrDefault() == password) { account.LoginAttempts = 0; result = _UserAccountAccessor.Value.UpdateAccount(account); if (result.IsSuccessful) { result.Activity = "Login"; } } else { account.LoginAttempts++; result = _UserAccountAccessor.Value.UpdateAccount(account); if (result.IsSuccessful) { result.IsSuccessful = false; result.Account = account; result.Reason = "Incorrect Password."; } } return result; }
public Result ValidatePassword(Account account, string password) { if (string.IsNullOrEmpty(password)) { return new Result() { IsSuccessful = false, Reason = "Please enter a password." }; } Debug.Assert(!string.IsNullOrEmpty(password)); if (account == null) { return new Result() { IsSuccessful = false, Reason = "Account was null." }; } Debug.Assert(account != null); if (!ValidPasswordStrength(password)) { return new Result() { IsSuccessful = false, Account = account, Activity = "Validate Password", Reason = "Password does not meet the acceptable password strength." }; } if (!account.Password.Contains(password)) { return new Result() { IsSuccessful = true, Account = account, Activity = "Validate Password" }; } //If this point is reached then the password validation failed. return new Result() { IsSuccessful = false, Account = account, Activity = "Validate Password", Reason = "Password does not meet the acceptable historical requirements." }; }
private Result UpdateAccountPassword(Account account, string password) { var isPasswordValid = _UserAccountEngine.Value.ValidatePassword(account, password); if (isPasswordValid.IsSuccessful) { isPasswordValid.Account.Password.Add(password); isPasswordValid.Account.PasswordLastChangedDate = DateTime.Now; if (isPasswordValid.Account.Password.Count == 4) { isPasswordValid.Account.Password.Remove(account.Password.FirstOrDefault()); } } return isPasswordValid; }