private static void ChangePasswordStrengthIndicator(Control label, string password) { if (label == null) { throw new ArgumentNullException("label"); } PasswordScore score = PasswordStrength.CheckStrength(password); Console.WriteLine(score); switch (score) { case PasswordScore.Blank: label.ForeColor = Color.Red; label.Text = @""; break; case PasswordScore.Weak: label.ForeColor = Color.Red; label.Text = @"Weak"; break; case PasswordScore.VeryWeak: label.ForeColor = Color.Red; label.Text = @"Very Weak"; break; case PasswordScore.Medium: label.ForeColor = Color.Orange; label.Text = @"Medium"; break; case PasswordScore.Strong: label.ForeColor = Color.Orange; label.Text = @"Strong"; break; case PasswordScore.VeryStrong: label.ForeColor = Color.Green; label.Text = @"Very Strong"; break; } }
private static void ChangePasswordStrengthIndicator(Label label, string password) { PasswordScore score = PasswordStrength.CheckStrength(password); Console.WriteLine(score); switch (score) { case PasswordScore.Blank: label.ForeColor = Color.Red; label.Text = @""; break; case PasswordScore.Weak: label.ForeColor = Color.Red; label.Text = @"Weak"; break; case PasswordScore.VeryWeak: label.ForeColor = Color.Red; label.Text = @"Very Weak"; break; case PasswordScore.Medium: label.ForeColor = Color.Orange; label.Text = @"Medium"; break; case PasswordScore.Strong: label.ForeColor = Color.Orange; label.Text = @"Strong"; break; case PasswordScore.VeryStrong: label.ForeColor = Color.Green; label.Text = @"Very Strong"; break; } }
private void SprawdzanieSilyHasla() { log_textbox.AppendText("\r\n ======================================\r\n" + SprawdzaczSilyHasla.CheckStrength(SSID, PASSWORD) + "\r\n ======================================\r\n"); }
public UserViewModel Register(RegisterViewModel viewModel) { if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } if (string.IsNullOrWhiteSpace(viewModel.Email)) { throw new ArgumentException(nameof(viewModel)); } if (string.IsNullOrWhiteSpace(viewModel.Password) || string.IsNullOrWhiteSpace(viewModel.PasswordConfirmation)) { throw new ArgumentException(nameof(viewModel)); } var duplicateUser = Repository.Where(x => x.Email == viewModel.Email).FirstOrDefault(); if (duplicateUser != null) { throw new DuplicateException("This user is dubplicate"); } if (viewModel.Password != viewModel.PasswordConfirmation) { throw new PasswordMismatchException(); } if (PasswordStrength.CheckStrength(viewModel.Password) < PasswordStrength.PasswordScore.Medium) { throw new WeakPasswordException(); } if (!viewModel.HasAcceptedTerms) { throw new TermsNotAcceptedException(); } var newUser = new User { UserId = Guid.NewGuid().ToString(), FirstName = viewModel.FirstName, LastName = viewModel.LastName, Email = viewModel.Email, LastLoggedIn = null, DateCreated = DateTime.UtcNow, PasswordHash = PasswordHash.HashPassword(viewModel.Password), Role = "User" }; try { Repository.Insert(newUser); Repository.SaveChanges(); } catch (DbUpdateException) { var ex = new DbUpdateException("Unable to save changes to the DB."); ex.Data.Add("AddedUser", newUser); throw ex; } return(new UserViewModel() { UserId = newUser.UserId, Email = newUser.Email, FirstName = newUser.FirstName, LastName = newUser.LastName, Role = newUser.Role }); }
public void CheckStrengthReturnsWeakForPasswordOfP455W9RdOnTheWeakPasswordList() { Assert.AreEqual(PasswordScore.Weak, PasswordStrength.CheckStrength("p455w0rd")); }
public void CheckStrengthReturnsVeryStrongForPasswordOf1234HelloWorld69WithExclaimationMark() { Assert.AreEqual(PasswordScore.VeryStrong, PasswordStrength.CheckStrength("!1234HelloWorld69")); }
public void CheckStrengthReturnsWeakForPasswordOfTrustno1OnTheWeakPasswordList() { Assert.AreEqual(PasswordScore.Weak, PasswordStrength.CheckStrength("TRUSTNO1")); }
public void CheckStrengthReturnsMediumForPasswordOfHelloWorld() { Assert.AreEqual(PasswordScore.Medium, PasswordStrength.CheckStrength("HelloWorld")); }
public void CheckStrengthReturnsStrongForPasswordOf1234HelloWorld69() { Assert.AreEqual(PasswordScore.Strong, PasswordStrength.CheckStrength("1234HelloWorld69")); }
public void CheckStrengthReturnsWeakForPasswordOfHello2() { Assert.AreEqual(PasswordScore.VeryWeak, PasswordStrength.CheckStrength("Hello2")); }
public void CheckStrengthReturnsEmptyForBlankPassword() { Assert.AreEqual(PasswordScore.Blank, PasswordStrength.CheckStrength("")); }
public void CheckStrengthReturnsWeakForPasswordOfPasswordOnTheWeakPasswordListIncludingNonCharacters() { Assert.AreEqual(PasswordScore.Weak, PasswordStrength.CheckStrength("p@$$w0rd")); }
public void CheckStrengthReturnsWeakForPasswordOfW3Lc0M3TheWeakPasswordList() { Assert.AreEqual(PasswordScore.Weak, PasswordStrength.CheckStrength("w3lc0m3")); }
public void CheckStrengthReturnsWeakForPasswordOfTrustN01TheWeakPasswordList() { Assert.AreEqual(PasswordScore.Weak, PasswordStrength.CheckStrength("trustn01")); }