public void ShouldGenerateIdempotentHash_WhenHashGenerateExecuteTwice() { var request = new SecurityRequest { ServiceName = "test", CommonName = "user", MasterPassword = "******" }; var hashGenerator = new PasswordHashGenerator(); var firstResult = hashGenerator.GenerateHash(request).GetAwaiter().GetResult(); var secondResult = hashGenerator.GenerateHash(request).GetAwaiter().GetResult(); Assert.Equal(firstResult, secondResult); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // not really used, but i hate the idea of storing passwords in plain text User.PasswordHash = PasswordHashGenerator.GenerateHash(User.PasswordHash); if (User.ProfilePicture == null) { User.ProfilePicture = "./img/user.png"; } _context.Attach(User).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(User.UserID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public void ShouldNotGenerateIdempotentHash_WhenDifferentVersion() { var request = new SecurityRequest { ServiceName = "test", CommonName = "user", MasterPassword = "******", Version = 1 }; var request2 = new SecurityRequest { ServiceName = "test", CommonName = "user", MasterPassword = "******", Version = 2 }; var hashGenerator = new PasswordHashGenerator(); var firstResult = hashGenerator.GenerateHash(request).GetAwaiter().GetResult(); var secondResult = hashGenerator.GenerateHash(request2).GetAwaiter().GetResult(); Assert.NotEqual(firstResult, secondResult); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // not really used, but i hate the idea of storing passwords in plain text User.PasswordHash = PasswordHashGenerator.GenerateHash(User.PasswordHash); if (User.ProfilePicture == null) { User.ProfilePicture = "./img/user.png"; } _context.Users.Add(User); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }