private void ChangePasswordButton_Click(object sender, RoutedEventArgs e) { if (0 == OldPasswordBox.Password.Length) { MessageBox.Show("请输入原密码!"); return; } if (0 == NewPasswordBox.Password.Length) { MessageBox.Show("请输入新密码!"); return; } if (0 == NewPasswordBox2.Password.Length) { MessageBox.Show("请输入密码确认!"); return; } if (NewPasswordBox.Password != NewPasswordBox2.Password) { MessageBox.Show("新密码与密码确认不一致!"); return; } string oldpw = OldPasswordBox.Password; string newpw = NewPasswordBox.Password; if (ChangeRootPassword(oldpw, newpw)) { MessageBox.Show("修改成功!"); OldPasswordBox.Clear(); NewPasswordBox.Clear(); NewPasswordBox2.Clear(); } else { MessageBox.Show("修改失败!"); } }
private void NewPasswordBoxRemove(object sender, MouseButtonEventArgs e) { NewPasswordBox.Clear(); }
private void ClearPasswordBoxes() { OldPasswordBox.Clear(); NewPasswordBox.Clear(); NewPasswordBox_Retype.Clear(); }
private void PasswordBoxClear() { PasswordBox.Clear(); NewPasswordBox.Clear(); NewPasswordBox_1.Clear(); }
private bool SubmitBtn() { bool ret = true; { try { if (Emailbox.Text == "") { lblNameIsRequired.Visible = true; ret = false; } else { lblNameIsRequired.Visible = false; } if (CurrentPasswordBox.Text == "") { lblEmailIsRequired.Visible = true; ret = false; } else { lblEmailIsRequired.Visible = false; } if (NewPasswordBox.Text == "") { lblPasswordIsRequired.Visible = true; ret = false; } else { lblPasswordIsRequired.Visible = false; } if (ConfirmPasswordBox.Text == "") { lblConfirmPasswordIsRequired.Visible = true; ret = false; } else { lblConfirmPasswordIsRequired.Visible = false; } //if (NewPasswordBox.Text != "" && ConfirmPasswordBox.Text != "") //{ // if (NewPasswordBox != ConfirmPasswordBox) // { // lblConfirmPasswordAndPasswordSame.Visible = true; // ret = false; // } //} //else //{ // lblConfirmPasswordAndPasswordSame.Visible = false; //} if ((Emailbox.Text != "") && (CurrentPasswordBox.Text != "") && (NewPasswordBox.Text != "") && (ConfirmPasswordBox.Text != "")) { //this is connection check email is exist if condtion is true so then check current password is exist into the database SqlCommand cmd = new SqlCommand("Select Count(*) From Admin Where E_mail = @E_mail", conn.connect); cmd.Parameters.AddWithValue("@E_mail", Emailbox.Text); conn.connect.Open(); int Result = (int)cmd.ExecuteScalar(); if (Result == 1) { //this connection is check that current password is exist SqlCommand cmd2 = new SqlCommand("Select Count(*) From Admin Where Password = @Password AND E_mail = @Email", conn.connect); cmd2.Parameters.AddWithValue("@Email", Emailbox.Text); cmd2.Parameters.AddWithValue("@Password", CurrentPasswordBox.Text); //conn.connect.Open(); int Result2 = (int)cmd2.ExecuteScalar(); //conn.connect.Close(); if (Result2 == 1) { if (NewPasswordBox.Text == ConfirmPasswordBox.Text) { SqlCommand cmd3 = new SqlCommand("update Admin Set Password=@Password where E_mail=@E_mail", conn.connect); cmd3.Parameters.AddWithValue("@E_mail", Emailbox.Text); cmd3.Parameters.AddWithValue("@Password", ConfirmPasswordBox.Text); cmd3.ExecuteNonQuery(); DialogResult Dr = MessageBox.Show("Password have changed", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); if (Dr == DialogResult.OK) { CurrentPasswordBox.Clear(); NewPasswordBox.Clear(); ConfirmPasswordBox.Clear(); } conn.connect.Close(); } else { lblConfirmPasswordIsRequired.Text = "Password does not match"; lblConfirmPasswordIsRequired.Visible = true; conn.connect.Close(); } } else { lblEmailIsRequired.Text = "Password does not exist"; lblEmailIsRequired.Visible = true; CurrentPasswordBox.Clear(); NewPasswordBox.Clear(); ConfirmPasswordBox.Clear(); conn.connect.Close(); } } else { lblNameIsRequired.Text = "Email does not exist"; lblNameIsRequired.Visible = true; Emailbox.Clear(); CurrentPasswordBox.Clear(); NewPasswordBox.Clear(); ConfirmPasswordBox.Clear(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(ret); } }