private void dataCheck() { MySqlConnection con = new MySqlConnection(); con.ConnectionString = login.dbConnection; string email = "select email, secword,secqn from users where email = '" + verifyEmail.email + "'"; MySqlDataReader ad; MySqlCommand com = new MySqlCommand(email, con); try { con.Open(); ad = com.ExecuteReader(); while (ad.Read()) { try { emailTxt = ad.GetString("email"); secwordTxt = ad.GetString("secword"); secqnTxt = ad.GetString("secqn"); } catch { if (MessageBox.Show("Sorry, this email does not contain a secret word. We are sorry to inform you that the password can not be reset. Please create another acount and remember to set the secret word for password reset. Thank you. ", "Information", MessageBoxButtons.OK) == DialogResult.OK) { this.Close(); login lg = new login(); lg.Show(); } } } ad.Close(); } catch (MySqlException ex) { MessageBox.Show(ex.Message); } con.Close(); }
private void bunifuThinButton21_Click(object sender, EventArgs e) { //sign up button MySqlConnection con = new MySqlConnection(); con.ConnectionString = login.dbConnection; string query = "insert into users(fname,lname,email,password,username,pin) values ('" + fname.Text + "', '" + lname.Text + "', '" + email.Text + "','" + GetMD5Hash(pwd.Text) + "','" + username.Text + "','" + pinLb.Text + "')"; string chek = "select email from users where email = '" + email.Text + "'"; string chek2 = "select username from users where username = '******'"; MySqlCommand com = new MySqlCommand(query, con); MySqlCommand com1 = new MySqlCommand(chek, con); MySqlCommand com2 = new MySqlCommand(chek2, con); try { con.Open(); MySqlDataReader reader; MySqlDataReader reader1; MySqlDataReader reader2; //checking if the username empty if (username.Text == "") { MessageBox.Show("Username Field can not be empty"); } else { //verifying if the password is correct if (pwd.Text == rtPwd.Text) { DataTable table1 = new DataTable(); reader1 = com1.ExecuteReader(); table1.Load(reader1); reader1.Close(); //checking if the email exist in the database if (table1.Rows.Count > 0) { MessageBox.Show("The enterd email, already exist. Please login", "Information", MessageBoxButtons.OK); email.Text = ""; } else { //Cheking if the user is already registerd DataTable table2 = new DataTable(); reader2 = com2.ExecuteReader(); table2.Load(reader2); reader2.Close(); if (table2.Rows.Count > 0) { MessageBox.Show("The enterd username, already exist. Please, change username", "Information", MessageBoxButtons.OK); username.Text = ""; } else { //verifying the email if is valid Regex reg = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); if (!reg.IsMatch(email.Text)) { MessageBox.Show("Please enter the valid email"); } else { string password = pwd.Text; //check if the password is strong bool validPassword = password.Any(char.IsDigit) && !password.All(char.IsLetterOrDigit) && password.Length >= 6; if (validPassword == true) { //creating the account reader = com.ExecuteReader(); reader.Close(); MessageBox.Show("Welcome,You have been added", "User added", MessageBoxButtons.OK); this.Close(); login lgn = new login(); lgn.Show(); } else { MessageBox.Show("The Password should contain at least letter, number,special character and should be more than 6 characters "); } } } } } else { MessageBox.Show("Password did not match"); } } } catch (MySqlException ex) { MessageBox.Show(ex.Message); } con.Close(); }