public AccountRegistration(Username username, Password password, FullName fullName, EmailAddress email) { Email = email; Username = username; Password = password; FullName = fullName; }
public ActionResult SignUp(AccountRegistration information) { var username = new Username(information.Username); bool usernameIsAvailable = _accountRegistrationService.IsUsernameAvailable(username); if (!usernameIsAvailable) { TempData.RegistrationFailureReason.Store(RegistrationFailureReason.UsernameNotAvailable); TempData.AccountRegistrationInformation.Store(information); return RedirectToAction<AccountController>(c => c.SignUp()); } var password = new Password(information.Password); var passwordConfirmation = new Password(information.PasswordConfirmation); if (!password.Equals(passwordConfirmation)) { TempData.RegistrationFailureReason.Store(RegistrationFailureReason.PasswordsDoNotMatch); return RedirectToAction<AccountController>(c => c.SignUp()); } var emailAddress = new EmailAddress(information.Email); var emailAddressConfirmation = new EmailAddress(information.EmailConfirmation); if (!emailAddress.Equals(emailAddressConfirmation)) { TempData.RegistrationFailureReason.Store(RegistrationFailureReason.EmailsDoNotMatch); return RedirectToAction<AccountController>(c => c.SignUp()); } var foo = new GivenNames(); var fullName = new FullName(new Name(information.LastName), new GivenNames(information.FirstName)); var accountRegistration = new AccountManagement.AccountRegistration(username, password, fullName, new EmailAddress(information.Email)); _accountRegistrationService.CreateAccount(accountRegistration); TempData.NewAccountUsername.Store(accountRegistration.Username); return RedirectToAction<AccountController>(c => c.SignUpComplete()); }
public LoginAttemptResult Authenticate(Username username, Password password) { Contract.Ensures(Contract.Result<LoginAttemptResult>().Succeeded == false || Contract.Result<LoginAttemptResult>().Account != null); Account account = _accountRepository.FindAccount(username); if (account == null) { return LoginAttemptResult.UsernameNotFound(); } SaltedHash accountPasswordHash = _accountRepository.GetAccountPassword(account.AccountId); bool passwordMatches = new Hasher().Matches(password.ToString(), accountPasswordHash); if (!passwordMatches) { int failedLoginAttemptCount = _accountRepository.IncrementFailedLoginAttemptCount(account.AccountId); return LoginAttemptResult.IncorrectPassword(failedLoginAttemptCount); } return LoginAttemptResult.Success(account); }
public HashedPassword Hash(Password password) { string empty = GenerateSalt(); return new HashedPassword(password.ToString(), empty); }
public bool Equals(Password password, HashedPassword hashedPassword) { string salt = hashedPassword.Salt; return string.Equals(Hash(password + salt), hashedPassword.ToString()); }