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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.