Advertisement
Guest User

Untitled

a guest
Jan 26th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. static bool ValidatePassword(string password)
  2. {
  3. const int MIN_LENGTH = 8;
  4. const int MAX_LENGTH = 64;
  5.  
  6. if (password == null) throw new ArgumentNullException();
  7.  
  8. bool meetsLengthRequirements = password.Length >= MIN_LENGTH && password.Length <= MAX_LENGTH;
  9. bool hasUpperCaseLetter = false;
  10. bool hasLowerCaseLetter = false;
  11. bool hasDecimalDigit = false;
  12.  
  13. if (meetsLengthRequirements)
  14. {
  15. foreach (char c in password)
  16. {
  17. if (char.IsUpper(c)) hasUpperCaseLetter = true;
  18. else if (char.IsLower(c)) hasLowerCaseLetter = true;
  19. else if (char.IsDigit(c)) hasDecimalDigit = true;
  20. }
  21. }
  22.  
  23. bool isValid = meetsLengthRequirements
  24. && hasUpperCaseLetter
  25. && hasLowerCaseLetter
  26. && hasDecimalDigit
  27. ;
  28. return isValid;
  29.  
  30. }
  31.  
  32.  
  33. bool IsValidEmail(string email)
  34. {
  35. try
  36. {
  37. var addr = new System.Net.Mail.MailAddress(email);
  38. return addr.Address == email;
  39. }
  40. catch
  41. {
  42. return false;
  43. }
  44. }
  45.  
  46.  
  47. private void bunifuFlatButton2_Click(object sender, EventArgs e)
  48. {
  49. Regex username = new Regex(@"^[a-zA-Z0-9]");
  50.  
  51. if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
  52. {
  53. System.Windows.Forms.MessageBox.Show("Fill out the required forms!");
  54. return;
  55. }
  56. else if (textBox2.Text != textBox3.Text)
  57. {
  58. System.Windows.Forms.MessageBox.Show("Your passwords are not matching");
  59. }
  60.  
  61. else if ((ValidatePassword(textBox2.Text) == true) || (IsValidEmail(textBox4.Text) == true) || username.Match(textBox1.Text).Success)
  62. {
  63. using (SqlConnection connection = new SqlConnection(connectionstring I know works))
  64. {
  65. SqlCommand cmd = new SqlCommand("INSERT INTO tabl_login (username, password, email) VALUES (@username, @password, @email)");
  66. cmd.CommandType = CommandType.Text;
  67. cmd.Connection = connection;
  68. cmd.Parameters.AddWithValue("@username", textBox1.Text);
  69. cmd.Parameters.AddWithValue("@password", textBox2.Text);
  70. cmd.Parameters.AddWithValue("@email", textBox4.Text);
  71. connection.Open();
  72. cmd.ExecuteNonQuery();
  73. }
  74.  
  75. MessageBox.Show("Congrats! You can sign in now!");
  76. Form2 objFrmMain = new Form2();
  77. this.Hide();
  78. objFrmMain.ShowDialog();
  79. this.Close();
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement