0

Hi,
I have a windows form that has three text boxes one each for the current password, new password and confirm new password . The purpose of the form is to allow a user to change his/her password and to confirm the change . I am using a Data access object (DAO) for communicating with the passwords database. The block of code that has been commented out shows my attempts so far at implement this. Can anyone guide me as to how to implement this bit of functionality?
Below is the code for the "save" button in the "Change Password" form.

private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                //byte passConfirm = 0;
                //string resultMsg = "";
                // Display message if user attempts to save data with blank fields
                if (txtCurrentPassword.Text.Trim().Equals("") ||
                    txtNewPassword.Text.Trim().Equals("") ||
                    txtConfirmPassword.Text.Trim().Equals(""))
                {
                    MessageBox.Show("Please enter your password.");
                    txtCurrentPassword.Focus();
                }
               // else if (txtCurrentPassword.Text.Trim() != aLogin.login(aPass));
               /* else // check if the user's input matches the current password
                {
                    passConfirm = aUserLogin.login(txtCurrentPassword.Text,ref resultMsg);
                    if (passConfirm == 1)
                    {
                        // Success. Pasword matches
                        User aNewPassword = new User(txtCurrentPassword.Text,
                                                     txtNewPassword.Text,
                                                     txtConfirmPassword.Text);

                    }
                }*/
                if (txtCurrentPassword.Text != txtNewPassword.Text ||
                    txtNewPassword.Text == txtConfirmPassword.Text)
                {

                    this.Close();
                }
                else
                {
                    MessageBox.Show("The passwords do not match.");
                    txtConfirmPassword.Text = "";
                    txtCurrentPassword.Text = "";
                    txtNewPassword.Text = "";
                }
            }// end try
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }// end btnSave_Click()method

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by JuhaW
0

I have used string.Compare or ComporeTo to compare strings. I think that equality function checks only that strings are really same instances.

PS
string.IsNullOrEmpty(oldpassword.Text) is very useful

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.