private void buttonUserCenter_Click(object sender, EventArgs e) { UserCenter userCenter = new UserCenter(username); this.Hide(); userCenter.ShowDialog(); this.Close(); }
private void btnSubmit_Click(object sender, EventArgs e) { try { string sql = "SELECT userPassword FROM user WHERE userName='******';"; MySqlCommand cmd = new MySqlCommand(sql, con); con.Open(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { passWord = reader.GetString("userPassword"); } if (textBoxPrePwd.Text == "") { MessageBox.Show("Please enter your password!"); } else if (textBoxPrePwd.Text == passWord) { string prePwd = textBoxPrePwd.Text; string newPwd = textBoxNewPwd.Text; string confirmPwd = textBoxConfirm.Text; if (prePwd == "" || newPwd == "" || confirmPwd == "") { MessageBox.Show("Invalid input!"); } else { if (newPwd.Length < 6) { MessageBox.Show("Password should have at least 6 characters!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBoxNewPwd.Text = ""; textBoxConfirm.Text = ""; } else if (!newPwd.Equals(confirmPwd)) { MessageBox.Show("Passwords different!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); textBoxNewPwd.Text = ""; textBoxConfirm.Text = ""; } else { string updatePassword = "******" + newPwd + "' where userPassword = '******'"; reader.Close(); MySqlCommand update = con.CreateCommand(); update.CommandText = updatePassword; update.ExecuteNonQuery(); con.Close(); MessageBox.Show("Successfully change your password!", "Success", MessageBoxButtons.OK); UserCenter userCenter = new UserCenter(username); this.Hide(); userCenter.ShowDialog(); this.Close(); } } } else { MessageBox.Show("Please enter the right password!"); } }catch (Exception ex) { MessageBox.Show("Please input something valid!"); } }