Saturday, 30 August 2014

how to change password in C#

private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtCurPass.Text != "")
            {
                if (Password() != txtCurPass.Text)
                {
                    MessageBox.Show("Incorrect Password", "Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCurPass.Focus();
                    txtCurPass.SelectAll();
                    return;
                }
                if (txtNewPass.Text.Trim() != "")
                {
                    if (txtConPass.Text.Trim() != "")
                    {
                        if (txtNewPass.Text.Trim() == txtConPass.Text.Trim())
                        {
                            string str = "Update T_LoginMain Set pw='" + txtConPass.Text.Trim() + "' Where username=" + "'" + txtUsername.Text.Trim() + "'";
                            con = new OleDbConnection(dbCon());
                            OleDbCommand cmd = new OleDbCommand(str, con);
                            con.Open();
                            cmd.ExecuteNonQuery();
                            con.Close();
                            MessageBox.Show("Password Changed", "Changed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            TextClear();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("New Password and Confirm Password must be same", "Same Password?", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            txtNewPass.Focus();
                            txtNewPass.SelectAll();
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Enter Password", "Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtConPass.Focus();
                        txtConPass.Focus();
                        txtConPass.SelectAll();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Enter Password", "Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtNewPass.Focus();
                    txtNewPass.SelectAll();
                    return;
                }
            }
            else
            {
                MessageBox.Show("Enter Current Password", "Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCurPass.Focus();
                txtCurPass.SelectAll();
                return;

            }

        }

No comments:

Post a Comment