public char PasswordCheck(string text, int charIndex, char addedChar) { if (inputField.text.Length + addedChar > 2) { string password = inputField.text + addedChar; PasswordScore passwordStrengthScore = PasswordAdvisor.CheckStrength(password); // Debug.Log(passwordStrengthScore + ": " + inputField.text + addedChar); switch (passwordStrengthScore) { case PasswordScore.Blank: case PasswordScore.VeryWeak: case PasswordScore.Weak: // Debug.Log("weak password"); passwordStrength.text = "weak password"; passwordStrength.color = new Color(255.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f); break; case PasswordScore.Medium: case PasswordScore.Strong: case PasswordScore.VeryStrong: // Debug.Log("strong password"); passwordStrength.text = "strong password"; passwordStrength.color = new Color(0.0f / 255.0f, 255.0f / 255.0f, 0.0f / 255.0f); break; } } return(addedChar); }
public PasswordScoreResult ScorePassword(string passwdToScore) { PasswordScoreResult httpResponse = new PasswordScoreResult(); httpResponse.Date = DateTime.Now; httpResponse.Tester = passwdToScore; int statusCode = (int)HttpStatusCode.OK; PasswordScore score = GenericHelpers.CheckStrength(passwdToScore); httpResponse.Score = score; httpResponse.Message = "Blank password!"; int result = (int)score; if (result <= (int)PasswordScore.Blank) { httpResponse.Message = "Blank password!"; } else if (result <= (int)PasswordScore.Weak) { httpResponse.Message = "Weak password, bad for you."; } else if (result <= (int)PasswordScore.Medium) { httpResponse.Message = "Medium password strength."; } else if (result <= (int)PasswordScore.VeryStrong) { httpResponse.Message = "Strong password. Good!"; } this.HttpContext.Response.StatusCode = statusCode; httpResponse.StatusCode = statusCode; return(httpResponse); }
public void PasswordHash_CheckStrength() { PasswordScore s = PasswordHash.CheckStrength(""); Assert.AreEqual(s, PasswordScore.Blank); s = PasswordHash.CheckStrength("abc"); Assert.AreEqual(s, PasswordScore.VeryWeak); s = PasswordHash.CheckStrength("abc"); Assert.AreEqual(s, PasswordScore.VeryWeak); s = PasswordHash.CheckStrength("sdfttsae"); Assert.AreEqual(s, PasswordScore.Weak); s = PasswordHash.CheckStrength("123456789ab"); Assert.AreEqual(s, PasswordScore.Medium); s = PasswordHash.CheckStrength("123456789abcd"); Assert.AreEqual(s, PasswordScore.Strong); s = PasswordHash.CheckStrength("#A23456789abcd"); Assert.AreEqual(s, PasswordScore.VeryStrong); }
public void GetPasswordScore_ShouldReturnScore_WhenPassedStrWithOnlyChars() { // arrange string original = "bob"; int expected = 1; string original2 = "bobbybob"; int expected2 = 2; string original3 = "bobbobbob"; int expected3 = 3; string original4 = "bobbobbobbob"; int expected4 = 3; var x = new PasswordScore(); // act var actual = x.GetPasswordScore(original); var actual2 = x.GetPasswordScore(original2); var actual3 = x.GetPasswordScore(original3); var actual4 = x.GetPasswordScore(original4); // assert Assert.Equal(expected, actual); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual3); Assert.Equal(expected4, actual4); }
public void ValidatePassword(string password, PasswordScore expectedScore) { var validator = new PasswordScoreValidator(); PasswordScore score = validator.CalculateScore(password); WriteToDebugConsoleWhenDebugging(password, validator); Assert.Equal(expectedScore, score); }
private void textBoxPassWord_TextChanged(object sender, EventArgs e) { labelPassWordE.ForeColor = Color.Red; labelPassWordE.Visible = false; if (textBoxPassWord.Text.Length > 4) { PasswordScore passwordStrengthScore = PasswordAdvisor.CheckStrength(textBoxPassWord.Text); switch (passwordStrengthScore) { case PasswordScore.Blank: labelPassWordE.ForeColor = Color.Red; labelPassWordE.Text = "Blank Password."; labelPassWordE.Visible = true; break; case PasswordScore.VeryWeak: labelPassWordE.ForeColor = Color.Red; labelPassWordE.Text = "Very Weak Password."; labelPassWordE.Visible = true; break; case PasswordScore.Weak: labelPassWordE.ForeColor = Color.DarkOrange; labelPassWordE.Text = "Weak Password."; labelPassWordE.Visible = true; passWordOK = true; break; case PasswordScore.Medium: labelPassWordE.ForeColor = Color.LimeGreen; labelPassWordE.Text = "Medium Password."; labelPassWordE.Visible = true; passWordOK = true; break; case PasswordScore.Strong: labelPassWordE.ForeColor = Color.Green; labelPassWordE.Text = "Strong Password."; labelPassWordE.Visible = true; passWordOK = true; break; case PasswordScore.VeryStrong: labelPassWordE.ForeColor = Color.Green; labelPassWordE.Text = "Very Strong Password."; labelPassWordE.Visible = true; passWordOK = true; break; } } else { labelPassWordE.ForeColor = Color.Red; labelPassWordE.Text = "Password must be more than 4 characters."; labelPassWordE.Visible = true; } }
public SignUpViewModel(TextBox tbUsername, PasswordBox pbPassword) { RegistrationCommand = new RelayCommand(e => { RegistrationPage registrationPage = new RegistrationPage(); SignUpPage.NavigationService.Navigate(registrationPage); }); LogInCommand = new RelayCommand(e => { UserDBContext = new UserDBContext(); UserRepo = new UserRepository <User>(UserDBContext); try { if (UserRepo.FindUser().FirstOrDefault(c => (c.Login == tbUsername.Text && c.Password == pbPassword.Password)).IsVerified == true) { Window win = (Window)SignUpPage.Parent; win.Close(); Mainvm.CurrentUser = UserRepo.FindUser().FirstOrDefault(c => (c.Login == tbUsername.Text && c.Password == pbPassword.Password)); MainWindow.DataContext = Mainvm; MainWindow.ShowDialog(); } } catch (Exception) { MessageBox.Show("Cant find", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }, ckPass => { string password = pbPassword.Password; PasswordScore passwordStrengthScore = PasswordAdvisor.CheckStrength(password); switch (passwordStrengthScore) { case PasswordScore.Blank: case PasswordScore.VeryWeak: return(false); case PasswordScore.Weak: case PasswordScore.Medium: case PasswordScore.Strong: case PasswordScore.VeryStrong: return(true); } return(false); }); }
public bool ValidatePassword(string password) { PasswordScore passwordStrength = CheckPasswordStrength(password); Debug.WriteLine($"{passwordStrength.ToString()}"); if ((int)passwordStrength >= (int)MinimumPasswordStrength) { return(true); } return(false); }
public void PasswordStrengthCheck() { if (inputField.text.Length >= 0) { string password = inputField.text; PasswordScore passwordStrengthScore = PasswordAdvisor.CheckStrength(password); // Debug.Log(passwordStrengthScore + ": " + inputField.text); switch (passwordStrengthScore) { case PasswordScore.Blank: passwordStrength.text = "Try a combination of factors, or increasing length"; passwordStrength.color = new Color(0.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f); break; case PasswordScore.VeryWeak: // Debug.Log("Very weak password"); passwordStrength.text = "Weaker password"; passwordStrength.color = new Color(255.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f); break; case PasswordScore.Weak: // Debug.Log("weak password"); passwordStrength.text = "Weak password"; passwordStrength.color = new Color(255.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f); break; case PasswordScore.Medium: // Debug.Log("Medium password"); passwordStrength.text = "Medium password"; passwordStrength.color = new Color(120.0f / 255.0f, 120.0f / 255.0f, 0.0f / 255.0f); break; case PasswordScore.Strong: // Debug.Log("Strong password"); passwordStrength.text = "Strong password"; passwordStrength.color = new Color(0.0f / 255.0f, 255.0f / 255.0f, 0.0f / 255.0f); break; case PasswordScore.VeryStrong: // Debug.Log("strong password"); passwordStrength.text = "Stronger password"; passwordStrength.color = new Color(21.0f / 255.0f, 181.0f / 255.0f, 109.0f / 255.0f); break; case PasswordScore.Secure: passwordStrength.text = "Long passwords should be your first concern, if nothing else"; passwordStrength.color = new Color(21.0f / 255.0f, 181.0f / 255.0f, 109.0f / 255.0f); break; } } }
public void CheckStrength() { Password = Password.Trim(); passwordScore = PasswordScore.AllOk; if (Password.Length < 1) { passwordScore = PasswordScore.Blank; return; } if (Password.Length < 8) { passwordScore = PasswordScore.CantLessthan8; return; } bool hasDigit = false, hasAlphbet = false, hasSpecial = false; for (int i = 0; i < Password.Length; i++) { if (char.IsLetter(Password[i])) { hasAlphbet = true; } else if (char.IsDigit(Password[i])) { hasDigit = true; } } if (!hasDigit) { passwordScore = PasswordScore.numericMiss; } else if (!hasAlphbet) { passwordScore = PasswordScore.AlphabetMiss; } else { bool temp = false; foreach (char c in Password) { if (specialCharcterAllowed.Contains(c)) { temp = true; } } if (!temp) { passwordScore = PasswordScore.SpecialMiss; } } }
public void GetPasswordScore_ShouldReturnScoreOfFive_WhenPassedStrOverLengthOverEightIncOneIntAndOneSpecChar() { // arrange var original = "bobbob1#2$"; var expected = 5; var x = new PasswordScore(); // act var actual = x.GetPasswordScore(original); // assert Assert.Equal(expected, actual); }
public void GetPasswordScore_ShouldReturnZero_WhenPassedEmptyString() { // arrange var original = String.Empty; int expected = 0; var x = new PasswordScore(); // act var actual = x.GetPasswordScore(original); // assert Assert.Equal(expected, actual); }
public PasswordScore PasswordStrength(String password) { /*SCORING LOGIC. * Divide 1 by number of password rules. The result is RequirementScore. * Get the password-score using Password.Strength. This is StrengthScore * Take the smaller of RequirementScore,StrengthScore. * Project it to appropriate strength string. */ double requirementScore = 0d; double strengthScore = 0d; int countRules = PasswordRules.Count(); int passedRules = countRules; if (countRules == 0) { requirementScore = 1; } else { var errors = PasswordRules.Where(r => !r.Holds(password)).Select(r => r.Name); if (errors != null) { passedRules = countRules - errors.Count(); } requirementScore = (double)passedRules / countRules; } strengthScore = Password.Strength(password); var score = Math.Min(requirementScore, strengthScore); PasswordScore[] passwordStrengthVerdicts = new[] { PasswordScore.VeryWeak, PasswordScore.Weak, PasswordScore.Average, PasswordScore.Strong, PasswordScore.VeryStrong }; score = score * passwordStrengthVerdicts.Length; int passwordVerdictIndex = Math.Min((int)score, passwordStrengthVerdicts.Length - 1); /* If resultScore is highest but requirementScore is less than 1. It means all password rules have not been met. Hence reduce strength by one level*/ if (passwordVerdictIndex == (passwordStrengthVerdicts.Length - 1) && requirementScore < 1) { passwordVerdictIndex -= 1; } PasswordScore resultScore = passwordStrengthVerdicts[passwordVerdictIndex]; return(resultScore); }
/// <summary> /// Show the value of security of a password after being evaluated /// </summary> /// <param name="NewPasswordTextbox">Textbox that contains the password</param> /// <param name="NewPasswordStrengthProgressBar">Progressbar that indicate the value of password strength</param> /// <param name="NewPasswordStrengthLabel">Label that indicate the value of password strength</param> public static void CheckPasswordStrength(TextBox NewPasswordTextbox, ProgressBar NewPasswordStrengthProgressBar, Label NewPasswordStrengthLabel) { PasswordScore passwordScore = CheckStrength(NewPasswordTextbox.Text); switch (passwordScore) { case PasswordScore.Empty: NewPasswordStrengthProgressBar.Visible = false; NewPasswordStrengthLabel.Visible = false; break; case PasswordScore.VeryWeak: NewPasswordStrengthProgressBar.Value = 20; NewPasswordStrengthLabel.ForeColor = Color.Red; NewPasswordStrengthLabel.Text = LanguageResx.ClientLanguage.passwordStrenght_VeryWeak; break; case PasswordScore.Weak: NewPasswordStrengthProgressBar.Value = 40; NewPasswordStrengthLabel.ForeColor = Color.Red; NewPasswordStrengthLabel.Text = LanguageResx.ClientLanguage.passwordStrenght_Weak; break; case PasswordScore.Medium: NewPasswordStrengthProgressBar.Value = 60; NewPasswordStrengthLabel.ForeColor = Color.DarkGoldenrod; NewPasswordStrengthLabel.Text = LanguageResx.ClientLanguage.passwordStrenght_Medium; break; case PasswordScore.Strong: NewPasswordStrengthProgressBar.Value = 80; NewPasswordStrengthLabel.ForeColor = Color.Green; NewPasswordStrengthLabel.Text = LanguageResx.ClientLanguage.passwordStrenght_Strong; break; case PasswordScore.VeryStrong: NewPasswordStrengthProgressBar.Value = 100; NewPasswordStrengthLabel.ForeColor = Color.Green; NewPasswordStrengthLabel.Text = LanguageResx.ClientLanguage.passwordStrenght_VeryStrong; break; } }
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; } }
public void GetPasswordScore_ShouldReturnScoreOfFour_WhenPassedStrOverCertainLengthIncOneInt() { // arrange var original = "bobbobbob1"; var expected = 4; var original2 = "bob1bobbob"; var expected2 = 4; var x = new PasswordScore(); // act var actual = x.GetPasswordScore(original); var actual2 = x.GetPasswordScore(original2); // assert Assert.Equal(expected, actual); Assert.Equal(expected2, actual2); }
private void textBoxPass_TextChanged(object sender, EventArgs e) { //label6.Text = textBoxPass.Text.Length.ToString(); string difficulty = ""; Color TextColor = SystemColors.Control; PasswordScore score = CheckStrength(textBoxPass.Text); switch (score) { case PasswordScore.Blank: difficulty = "None"; TextColor = Color.Gray; break; case PasswordScore.VeryWeak: difficulty = "VeryWeak"; TextColor = Color.Red; break; case PasswordScore.Weak: difficulty = "Weak"; TextColor = Color.Orange; break; case PasswordScore.Medium: difficulty = "Medium"; TextColor = Color.Yellow; break; case PasswordScore.Strong: difficulty = "Strong"; TextColor = Color.YellowGreen; break; case PasswordScore.VeryStrong: difficulty = "VeryStrong"; TextColor = Color.Green; break; } label6.Text = $"{difficulty}"; label6.ForeColor = TextColor; }
public bool Validate() { PasswordScore passwordStrengthScore = PasswordAdvisor.CheckStrength(this); switch (passwordStrengthScore) { case PasswordScore.Blank: this.Message = "Password Invalid"; this.MessageColor = Brushes.Red; return(false); case PasswordScore.VeryWeak: this.Message = "Password Very Weak"; this.MessageColor = Brushes.OrangeRed; return(false); case PasswordScore.Weak: this.Message = "Password Weak"; this.MessageColor = Brushes.Orange; return(true); case PasswordScore.Medium: this.Message = "Password Medium"; this.MessageColor = Brushes.Yellow; return(true); case PasswordScore.Strong: this.Message = "Password Strong"; this.MessageColor = Brushes.GreenYellow; return(true); case PasswordScore.VeryStrong: this.Message = "Password Very Strong"; this.MessageColor = Brushes.Green; return(true); } return(false); }
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; } }
public void GetPasswordScore_ShouldReturnScoreOfSix_WhenPassedStrOverLengthOverTwelveIncOneIntAndOneSpecChar() { // arrange var original = "bobbobbob1!2@3#"; var expected = 7; var original2 = "#bob1bo!b2bob@3"; var expected2 = 7; var original3 = "#123bobbo!bbob@%&/"; var expected3 = 7; var x = new PasswordScore(); // act var actual = x.GetPasswordScore(original); var actual2 = x.GetPasswordScore(original2); var actual3 = x.GetPasswordScore(original3); // assert Assert.Equal(expected, actual); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual3); }
public void GetPasswordScore_ShouldReturnScoreOfSix_WhenPassedStrOverLengthOverTwelveIncOneInt() { // arrange var original = "bobbobbobbob123"; var expected = 6; var original2 = "bob1bob2bob3bob"; var expected2 = 6; var original3 = "bobbob280bobbob"; var expected3 = 6; var x = new PasswordScore(); // act var actual = x.GetPasswordScore(original); var actual2 = x.GetPasswordScore(original2); var actual3 = x.GetPasswordScore(original3); // assert Assert.Equal(expected, actual); Assert.Equal(expected2, actual2); Assert.Equal(expected3, actual3); }
void passwordchecker() { string test = txt_RegPassword.TextLength.ToString(); String password = test; // Substitute with the user input string PasswordScore passwordStrengthScore = PasswordAdvisor.CheckStrength(password); switch (passwordStrengthScore) { case PasswordScore.Blank: case PasswordScore.VeryWeak: case PasswordScore.Weak: // Show an error message to the user break; case PasswordScore.Medium: case PasswordScore.Strong: case PasswordScore.VeryStrong: // Password deemed strong enough, allow user to be added to database etc break; } MessageBox.Show(passwordStrengthScore.ToString()); }
static void Main(string[] args) { string menuoption; string password; string confirmedPassword; string specifiedUsername; string newPassword; Console.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); Console.WriteLine("Welcome to Josh's Password Reset Program"); Console.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); while (true) { Console.WriteLine("Would you like to:"); Console.WriteLine("(C)heck a password and determine its strength"); Console.WriteLine("(R)eset a password in the text document"); Console.WriteLine("(A)dd a username and password to the text document"); Console.WriteLine("(O)mit a username and password from the text document"); Console.WriteLine("(E)ncrypt a password manually"); Console.WriteLine("(D)ecrypt a password manually"); Console.WriteLine("E(x)it the program"); menuoption = Console.ReadLine().ToUpper(); if (menuoption == "X") { Environment.Exit(0); } if (menuoption == "C") { Console.WriteLine("Please input a password"); password = ReadPassword(); while (password.Length < 8) { Console.WriteLine("Invalid password - please use 8 or more characters"); password = ReadPassword(); } while (password.Any(char.IsUpper) != true || password.Any(char.IsLower) != true) { Console.WriteLine("Invalid password - please use a mixture of upper and lower case characters"); password = ReadPassword(); } Console.WriteLine("Please confirm your password"); confirmedPassword = ReadPassword(); while (confirmedPassword != password) { Console.WriteLine("These passwords do not match. Please try again."); confirmedPassword = ReadPassword(); } Console.WriteLine("The password you have entered is valid."); PasswordScore score = CheckStrength(password); Console.WriteLine("Your password is of " + score + " strength"); Console.WriteLine("Press enter to check another password"); Console.ReadLine(); Console.Clear(); } if (menuoption == "R") { StreamReader sr = new StreamReader(path); Console.WriteLine("Which username would you like to modify the password of?"); specifiedUsername = Console.ReadLine(); replaceText = false; while (!sr.EndOfStream) // Cycles through all of the lines of text in the txt file { string username = sr.ReadLine(); if (specifiedUsername == username) // Checks if the user has typed a valid username { Console.WriteLine("Please type the password you would like to change"); string oldPassword = ReadPassword(); string nextLine = sr.ReadLine(); DecryptText(nextLine, keyword); decryptedPassword = decryptResult; if (oldPassword == decryptedPassword) // Checks if the user has typed the password below that username { Console.WriteLine("What would you like your new password to be?"); newPassword = ReadPassword(); while (newPassword.Length < 8) { Console.WriteLine("Invalid password - please use 8 or more characters"); newPassword = ReadPassword(); } while (newPassword.Any(char.IsUpper) != true || newPassword.Any(char.IsLower) != true) { Console.WriteLine("Invalid password - please use a mixture of upper and lower case characters"); newPassword = ReadPassword(); } Console.WriteLine("Please confirm your new password"); confirmedPassword = ReadPassword(); if (newPassword == confirmedPassword) { EncryptText(newPassword, keyword); newPassword = encryptResult; entireFile = File.ReadAllText(path); entireFile = entireFile.Replace(nextLine, newPassword); replaceText = true; PasswordScore score = CheckStrength(newPassword); Console.WriteLine("Your password is of " + score + " strength"); } } if (nextLine.IndexOf(oldPassword, StringComparison.CurrentCultureIgnoreCase) == 1) { break; } } } if (replaceText == true) { sr.Close(); File.WriteAllText(path, entireFile); Console.WriteLine("Press enter to continue..."); Console.ReadLine(); Console.Clear(); } if (replaceText == false) { Console.WriteLine("You have typed the wrong username/password. Please try again."); Console.ReadLine(); Console.Clear(); } } if (menuoption == "A") { string [] entireFileArray = File.ReadAllLines(path); Console.WriteLine("What would you like your new username to be? "); string newUsername = Console.ReadLine(); bool usernameExists = entireFileArray.Contains(newUsername); while (usernameExists == true) { Console.WriteLine("That username already exists, please pick again."); newUsername = Console.ReadLine(); usernameExists = entireFileArray.Contains(newUsername); } Console.WriteLine("Please enter your new password."); string NewPassword = ReadPassword(); while (NewPassword.Length < 8) { Console.WriteLine("Invalid password - please use 8 or more characters"); NewPassword = ReadPassword(); } while (NewPassword.Any(char.IsUpper) != true || NewPassword.Any(char.IsLower) != true) { Console.WriteLine("Invalid password - please use a mixture of upper and lower case characters"); NewPassword = ReadPassword(); } Console.WriteLine("Please confirm your new password."); string ConfirmedPassword = ReadPassword(); if (ConfirmedPassword == NewPassword) { EncryptText(NewPassword, keyword); string encryptedPassword = encryptResult; using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(newUsername); sw.WriteLine(encryptedPassword); } } } if (menuoption == "O") { string[] entireFileArray = File.ReadAllLines(path); Console.WriteLine("Which username and password would you like to omit?"); Console.WriteLine("Username:"******"Password:"******"That username does not exist, please try again."); usernametoDelete = Console.ReadLine(); usernameExists = entireFileArray.Contains(usernametoDelete); } EncryptText(passwordtoDelete, keyword); string encryptedPassword = encryptResult; bool passwordExists = entireFileArray.Contains(encryptedPassword); while (passwordExists != true) { Console.WriteLine("That password does not exist, please try again."); passwordtoDelete = ReadPassword(); passwordExists = entireFileArray.Contains(usernametoDelete); } Console.WriteLine("Are you sure you would like to continue? Once they have been deleted, they cannot be recovered."); string deletePassword = Console.ReadLine().ToUpper(); if (deletePassword == "Y") { for (int i = 0; i < entireFileArray.Length; i++) // Creates a for loop that will cycle through the file { string line = entireFileArray[i]; // Sets the variable line to the current line being checked if (line == usernametoDelete || line == encryptedPassword) // If the line has either the username or password that needs to be deleted { entireFileArray[i] = ""; // Set the line with the username/password to null } } string[] newFile = entireFileArray.Where(str => !string.IsNullOrEmpty(str)).ToArray(); // Defines a new array that takes the null area where the username/password was and omits it File.WriteAllLines(path, newFile); // Writes this new array to the text file } } if (menuoption == "E") { Console.WriteLine("Please type the password you would like to encrypt: "); input = Console.ReadLine(); EncryptText(input, keyword); Console.WriteLine(encryptResult); Console.ReadLine(); Console.Clear(); } if (menuoption == "D") { Console.WriteLine("Please type the hash created from the encryption: "); input = Console.ReadLine(); DecryptText(input, keyword); Console.WriteLine(decryptResult); Console.ReadLine(); Console.Clear(); } } }
private void txtPassword_Leave(object sender, EventArgs e) { if (txtPassword.Text == String.Empty) { txtPassword.Text = sysMessages.msgEnterPassword; txtPassword.SelectAll(); txtPassword.Focus(); } string pw = txtPassword.Text; PasswordScore pScore = PasswordAdvisor.CheckStrength(pw); switch (pScore) { case PasswordScore.Blank: { txtStrength.BackColor = Color.Red; txtStrength.ForeColor = Color.White; txtStrength.Text = sysMessages.msgBlank; break; } case PasswordScore.VeryWeak: { txtStrength.BackColor = Color.Orange; txtStrength.ForeColor = Color.White; txtStrength.Text = sysMessages.msgVeryWeak; break; } case PasswordScore.Weak: { txtStrength.BackColor = Color.Yellow; txtStrength.ForeColor = Color.Black; txtStrength.Text = sysMessages.msgWeak; break; } case PasswordScore.Medium: { txtStrength.BackColor = Color.Green; txtStrength.ForeColor = Color.White; txtStrength.Text = sysMessages.msgMedium; break; } case PasswordScore.Strong: { txtStrength.BackColor = Color.SkyBlue; txtStrength.ForeColor = Color.Black; txtStrength.Text = sysMessages.msgStrong; break; } case PasswordScore.VeryStrong: { txtStrength.BackColor = Color.Blue; txtStrength.ForeColor = Color.White; txtStrength.Text = sysMessages.msgVeryStrong; break; } } }
// GET api/values/5 public IHttpActionResult GetPassword(string password) { PasswordScore passwordStrengthScore = PasswordChecker.Application.PasswordChecker.CheckStrength(password); return(Ok(passwordStrengthScore)); }
public RegistrationViewModel(TextBox firstname, TextBox lastname, TextBox phonenumber, TextBox mail, TextBox username, PasswordBox password, PasswordBox confirmpassword, TextBox verifycode, Page currentpage) { int oldran = newran; SendCodeCommand = new RelayCommand(e => { if (password.Password == confirmpassword.Password) { try { ////////MAIL PART////// SmtpClient smtp = new SmtpClient(); int port = int.Parse(ConfigurationManager.AppSettings["SMTP_TLS"]); string host = ConfigurationManager.AppSettings["SMTP_Server_Adress"]; smtp.EnableSsl = true; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.Host = host; smtp.Port = port; string mypass = ConfigurationManager.AppSettings["MyPassword"]; string mylog = ConfigurationManager.AppSettings["MyLogin"]; smtp.Credentials = new NetworkCredential(mylog, mypass); ////////MAIL MESSAGE PART///////// MailMessage message = new MailMessage(); message.From = new MailAddress(mylog); message.To.Add(mail.Text); message.Subject = ConfigurationManager.AppSettings["Subject"]; message.Body = $@"In order to help maintain the security of your EyeTaxi account we sent you this verification code: {newran} "; smtp.Send(message); MessageBox.Show("Please Verify Your Email"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }, checkCells => { if (firstname.Text.Length > 1 && lastname.Text.Length > 1 && phonenumber.Text.Length > 6) { PasswordScore passwordStrengthScore = PasswordAdvisor.CheckStrength(password.Password); switch (passwordStrengthScore) { case PasswordScore.Blank: case PasswordScore.VeryWeak: return(false); case PasswordScore.Weak: case PasswordScore.Medium: case PasswordScore.Strong: case PasswordScore.VeryStrong: if (password.Password == confirmpassword.Password) { return(true); } break; } } return(false); }); SignUpCommand = new RelayCommand(e => { if (verifycode.Text == oldran.ToString()) { UserDBContext = new UserDBContext(); UserRepo = new UserRepository <User>(UserDBContext); User user = new User(); user.LastName = lastname.Text.ToString(); user.FirstName = firstname.Text.ToString(); user.Email = mail.Text.ToString(); user.PhoneNumber = phonenumber.Text.ToString(); user.Login = username.Text.ToString(); user.Password = password.Password.ToString(); user.IsVerified = true; UserRepo.Add(user); UserDBContext.SaveChanges(); MessageBox.Show("SUCCESS!!!"); currentpage.NavigationService.Navigate(new SignUpPage()); } else { MessageBox.Show("Your Verification Code is not correct"); } }); }
public static PasswordStrengthValidator BasicPassword(this ControlValidatorInjector controlValidator, int minimumLength = 8, PasswordScore minimumScore = PasswordScore.Strong) { var validator = controlValidator.AddValidator <PasswordStrengthValidator>(Resources.Validation.PasswordDoesNotMatchRequirements); validator.MinimumLength = minimumLength; validator.MinimumScore = minimumScore; return(validator); }
public PasswordNotStrongEnoughException(PasswordScore passwordScore) : base($"Password is not strong enough, PasswortScore is {passwordScore}") { }
private void btnNext_Click(object sender, EventArgs args) { // Variables bool firstNameTest; bool lastNameTest; bool emailTest; bool NameTest; bool EmailTest; bool PasswordTest; bool AllTestsPassed; string appendError = ""; // Connect to inputed text EditText etFirstName = (EditText)FindViewById(Resource.Id.etFirstName); EditText etLastName = (EditText)FindViewById(Resource.Id.etLastName); EditText etEmail = (EditText)FindViewById(Resource.Id.etEmail); EditText etPassword = (EditText)FindViewById(Resource.Id.etPassword); EditText etConfirmPassword = (EditText)FindViewById(Resource.Id.etConfirmPassword); TextView tvPromptErrors = (TextView)FindViewById(Resource.Id.tvPromptErrors); // Test to make sure first and last name are all chars firstNameTest = IsAllAlphabetic(etFirstName.Text); lastNameTest = IsAllAlphabetic(etLastName.Text); if (firstNameTest == true && lastNameTest == true) { // Do nothing move on to next test NameTest = true; } else { // Append to list of errors to be displayed to user NameTest = false; Context context = ApplicationContext; appendError += "First and last name cannot contain any numbers or special characters" + "\n"; //Toast toast = Toast.MakeText(context, appendError, Android.Widget.ToastLength.Long); //toast.Show(); } ValidEmail email = new ValidEmail(); // Test to make sure email is in correct format emailTest = email.IsValidEmail(etEmail.Text); if (email.IsValidEmail(etEmail.Text)) { // Do nothing go to next test EmailTest = true; } else { // Append to list of errors to be displayed to user EmailTest = false; Context context = ApplicationContext; appendError += "Please make sure email is in correct format ex. [email protected]" + "\n"; } // Test to make sure password is strong PasswordScore passwordStrengthScore = PasswordAdvisor.CheckStrength(etEmail.Text); switch (passwordStrengthScore) { case PasswordScore.VeryWeak: case PasswordScore.Weak: // Send toast for error Context context = ApplicationContext; appendError += "Please make sure password is at least 6 charcters, Uppercase and special charcter" + "\n"; break; case PasswordScore.Medium: case PasswordScore.Strong: case PasswordScore.VeryStrong: // Password deemed strong enough, allow user to be added to database etc PasswordTest = true; break; } // Compare both feilds of inputed password to make sure they are correct bool checkIfEqual = String.Equals(etPassword.Text, etConfirmPassword.Text); if (checkIfEqual == true) { // Go to next test PasswordTest = true; } else { // Append to list of errors to be displayed to user PasswordTest = false; Context context = ApplicationContext; appendError += "Passwords do not match" + "\n"; } // Check to make sure all feilds are filled out if (etFirstName.Length() != 0 && etLastName.Length() != 0 && etEmail.Length() != 0 && etPassword.Length() != 0 && etConfirmPassword.Length() != 0) { // Filed is not empty do your code here. AllTestsPassed = true; } else { // Append to list of errors to be displayed to user AllTestsPassed = false; Context context = ApplicationContext; appendError += "Please fill out all fields" + "\n"; } // If all tests pass procced to next page if (AllTestsPassed == true && PasswordTest == true && NameTest == true && EmailTest == true) { //etFirstName WebClient client = new WebClient(); Uri uri = new Uri("http://packstudy-com.stackstaging.com/registration.php"); NameValueCollection parameter = new NameValueCollection(); parameter.Add("FirstName", etFirstName.Text); parameter.Add("LastName", etLastName.Text); parameter.Add("Email", etEmail.Text); parameter.Add("Password", etPassword.Text); parameter.Add("PhoneNumber", "123456789"); byte[] returnValue = client.UploadValues(uri, parameter); string r = Encoding.ASCII.GetString(returnValue); if (r == "Sucess") { uri = new Uri("http://packstudy-com.stackstaging.com/login.php"); parameter = new NameValueCollection(); parameter.Add("Email", etEmail.Text); parameter.Add("Password", etPassword.Text); returnValue = client.UploadValues(uri, parameter); r = Encoding.ASCII.GetString(returnValue); List <User> users = JsonConvert.DeserializeObject <List <User> >(r); User CurrentUser = users[0]; //since the user name and password work, store it in the shared prefrences ISharedPreferences sharedPrefrences = GetSharedPreferences("MyData", FileCreationMode.Private); var prefEditor = sharedPrefrences.Edit(); prefEditor.PutInt("id", CurrentUser.Id); prefEditor.PutString("FirstName", CurrentUser.FirstName); prefEditor.PutString("LastName", CurrentUser.LastName); prefEditor.PutString("Email", CurrentUser.Email); prefEditor.PutString("Password", CurrentUser.Password); prefEditor.PutString("PhoneNumber", CurrentUser.PhoneNumber); prefEditor.PutString("Username", CurrentUser.Username); prefEditor.Commit(); // Go to next page Intent activityIntent = new Intent(this, typeof(SelectCourses)); StartActivity(activityIntent); } else { Context context = ApplicationContext; appendError += "Did not upload to database correctly"; } } else { // prompt errors that need to be fixed tvPromptErrors.Text = appendError; // Reset errors prompt appendError = ""; } }