public void CalculateHash_CorrectDataAfterFirstTime_Calculated(string password, byte[] passwordSalt) { // Arrange var passwordManager = new PasswordManager(); // Act passwordManager.CalculatePasswordHash(password, passwordSalt, out byte[] firstPasswordHash); passwordManager.CalculatePasswordHash(password, passwordSalt, out byte[] secondPasswordHash); // Assert Assert.NotEqual(default(byte[]), firstPasswordHash); Assert.Equal(firstPasswordHash, secondPasswordHash); }
public override IEnumerable <object[]> GetData(MethodInfo testMethod) { manager.CalculatePasswordHash("pass123!", out byte[] salt, out byte[] hash); yield return(new object[] { new Account("User", hash, salt), "pass123!", true }); yield return(new object[] { new Account("User", hash, salt), "guess?1", false }); yield return(new object[] { new Account("User", hash, salt), null, false }); }
public async Task AddAccountAsync(CreateAccount command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (string.IsNullOrEmpty(command.Password) || string.IsNullOrEmpty(command.Login)) { command.Login = "******"; command.Password = "******"; } byte[] passwordSalt, passwordHash; var avatar = await _context.Avatars.FirstOrDefaultAsync(); _passwordManager.CalculatePasswordHash(command.Password, out passwordSalt, out passwordHash); var account = new Account(command.Login, passwordHash, passwordSalt, avatar); await _context.Accounts.AddAsync(account); await _context.SaveChangesAsync(); }
public void CalculateHash_CorrectDataForFirstTime_Calculated(string password) { // Arange var passwordManager = new PasswordManager(); // Act passwordManager.CalculatePasswordHash(password, out byte[] passwordSalt, out byte[] passwordHash); // Assert Assert.NotEqual(default(byte[]), passwordHash); Assert.NotEqual(default(byte[]), passwordSalt); }
public Account(string password, string login) { var manager = new PasswordManager(); byte[] passwordHash, salt; manager.CalculatePasswordHash(password, out passwordHash, out salt); PasswordHash = passwordHash; Salt = salt; Login = login; }
public void CalculateHash_CorrectData_Calculated(string password) { // Arrange var passwordManager = new PasswordManager(); AccountPasswordData accountPasswordData; // Act accountPasswordData = passwordManager.CalculatePasswordHash(password); // Assert Assert.NotEqual(default(byte[]), accountPasswordData.Salt); Assert.NotEqual(default(byte[]), accountPasswordData.PasswordHash); }