Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static bool ValidatePassword(string password)
- {
- const int MIN_LENGTH = 8;
- const int MAX_LENGTH = 64;
- if (password == null) throw new ArgumentNullException();
- bool meetsLengthRequirements = password.Length >= MIN_LENGTH && password.Length <= MAX_LENGTH;
- bool hasUpperCaseLetter = false;
- bool hasLowerCaseLetter = false;
- bool hasDecimalDigit = false;
- if (meetsLengthRequirements)
- {
- foreach (char c in password)
- {
- if (char.IsUpper(c)) hasUpperCaseLetter = true;
- else if (char.IsLower(c)) hasLowerCaseLetter = true;
- else if (char.IsDigit(c)) hasDecimalDigit = true;
- }
- }
- bool isValid = meetsLengthRequirements
- && hasUpperCaseLetter
- && hasLowerCaseLetter
- && hasDecimalDigit
- ;
- return isValid;
- }
- bool IsValidEmail(string email)
- {
- try
- {
- var addr = new System.Net.Mail.MailAddress(email);
- return addr.Address == email;
- }
- catch
- {
- return false;
- }
- }
- private void bunifuFlatButton2_Click(object sender, EventArgs e)
- {
- Regex username = new Regex(@"^[a-zA-Z0-9]");
- if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
- {
- System.Windows.Forms.MessageBox.Show("Fill out the required forms!");
- return;
- }
- else if (textBox2.Text != textBox3.Text)
- {
- System.Windows.Forms.MessageBox.Show("Your passwords are not matching");
- }
- else if ((ValidatePassword(textBox2.Text) == true) || (IsValidEmail(textBox4.Text) == true) || username.Match(textBox1.Text).Success)
- {
- using (SqlConnection connection = new SqlConnection(connectionstring I know works))
- {
- SqlCommand cmd = new SqlCommand("INSERT INTO tabl_login (username, password, email) VALUES (@username, @password, @email)");
- cmd.CommandType = CommandType.Text;
- cmd.Connection = connection;
- cmd.Parameters.AddWithValue("@username", textBox1.Text);
- cmd.Parameters.AddWithValue("@password", textBox2.Text);
- cmd.Parameters.AddWithValue("@email", textBox4.Text);
- connection.Open();
- cmd.ExecuteNonQuery();
- }
- MessageBox.Show("Congrats! You can sign in now!");
- Form2 objFrmMain = new Form2();
- this.Hide();
- objFrmMain.ShowDialog();
- this.Close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement