public async Task encryptPasswordAsync_EncryptPassword_EncryptPasswordSuccessful(string password, int UserID) { UserAccountRepository userAccountRepo = new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData()); // Act ICryptographyService CryptographyService = new CryptographyService(userAccountRepo); string encryptedPassedPassword = await CryptographyService.EncryptPasswordAsync(password, UserID); var userAccount = await userAccountRepo.GetAccountById(UserID); var encryptedPassword = userAccount.Password; string salt = await userAccountRepo.GetSaltById(UserID); string SaltedPassword = password + salt; byte[] Data = System.Text.Encoding.ASCII.GetBytes(SaltedPassword); Data = new System.Security.Cryptography.SHA256Managed().ComputeHash(Data); string testPassword = System.Text.Encoding.ASCII.GetString(Data).ToString(); //Assert Assert.IsTrue(testPassword == encryptedPassedPassword); }
public async Task ChangePasswordTest_UserPasswordChanges_PasswordChangeCompletes(int userId, string password, string newPassword) { IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString); IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString); ICryptographyService cryptographyService = new CryptographyService(userAccountRepository); IAuthenticationService authenticationService = new AuthenticationService(userAccountRepository); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService); bool result = await userAccountSettingsManager.ChangePasswordAsync(password, newPassword, userId); if (!result) { Assert.IsTrue(false); } UserAccountModel model = await userAccountRepository.GetAccountById(userId); UserAccountRepository userAccountRepo = new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData()); string encryptedNewPassword = await cryptographyService.EncryptPasswordAsync(newPassword, userId); if (model.Password == encryptedNewPassword) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }