free geoip Change Password Dialog Box -- Code - Jayson's Blog - jaysonKnight.com
jaysonKnight.com
Welcome to my corner of the internet

Change Password Dialog Box -- Code

[Update 11/26/2004] Removed line numbers to alleviate cut/paste issues.

 

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Web.Services.Protocols;

using System.Windows.Forms;

using System.Data;

 

namespace ArmsClient{

      /// <summary>

      /// Change the logged on user's password.

      /// </summary>

      /// <remarks>

      /// This form is used to change the logged on user's password.  Validation is run

      /// against the user's input to ensure all fields have values, and that the new password

      /// textbox matches the confirm password textbox.

      /// </remarks>

      public class ChangePassword : System.Windows.Forms.Form

      {

 

            #region Control Declarations

 

            private System.Windows.Forms.Button changePasswordButton;

            private System.Windows.Forms.TextBox oldPasswordTextBox;

            private System.Windows.Forms.TextBox newPasswordTextBox;

            private System.Windows.Forms.TextBox confirmPasswordTextBox;

            private System.Windows.Forms.Label oldPasswordLabel;

            private System.Windows.Forms.Label newPasswordLabel;

            private System.Windows.Forms.Label confirmPasswordLabel;

            private System.Windows.Forms.ErrorProvider passwordMatchProvider;

            private System.Windows.Forms.Button cancelButton;

           

            /// <summary>

            /// Required designer variable.

            /// </summary>

            private System.ComponentModel.Container components = null;

            private System.Windows.Forms.Label errorLabel;

            #endregion

 

            #region Member Vars

 

            /// <summary>

            /// these constants are used

            /// to detect if the form's close button was clicked.

            /// </summary>

            private const int SC_CLOSE = 0xF060;

            private const int WM_SYSCOMMAND = 0x0112;

 

            /// <summary>

            /// These constants are used for validation errors.

            /// </summary>

            private const string PASSWORD_MISMATCH_ERROR          = "The passwords did not not match.  Please try again.";

            private const string PASSWORD_BLANK_ERROR             = "This field cannot be blank.  Please enter a value.";

            private const string MULTIPLE_PASSWORD_BLANK_ERROR    = "These fields cannot be blank.  Please enter a value.";

           

            /// <summary>

            /// Variable used for the name of the error label, used down the line to clear the text

            /// of the label.

            /// </summary>

            private string _errorLabelName;

 

            /// <summary>

            /// Variables to use for public properties to return password values

            /// </summary>

            private string _oldPassword;

            private string _newPassword;

 

            /// <summary>

            /// Variable used to see if the control closing the form needs to shortcircuit validation.

            /// </summary>

            private bool _isCancelleable = false;

            #endregion

 

            #region Delegates

 

            /// <summary>

            /// Delegate used for changing focus to the appropriate control.

            /// </summary>

            /// <remarks>

            /// This is necessary due to the ErrorProvider locking a control's focus.  Calling

            /// this delegate on a control's BeginInvoke sends a message to the form which

            /// is processed after all other event handlers.

            /// </remarks>

            private delegate void setFocusEventHandler(Control ctrl);

            #endregion

 

            #region Constructors

     

            /// <summary>

            /// Default constructor.

            /// </summary>

            public ChangePassword()

            {

                  //

                  // Required for Windows Form Designer support

                  //

                  InitializeComponent();

            }

            #endregion

 

            #region Form Overrides

            /// <summary>

            /// Clean up any resources being used.

            /// </summary>

            protected override void Dispose( bool disposing )

            {

                  if( disposing )

                  {

                        if (components != null)

                        {

                              components.Dispose();

                        }

                  }

                  base.Dispose( disposing );

            }

            #endregion

 

            #region Windows Form Designer generated code

            /// <summary>

            /// Required method for Designer support - do not modify

            /// the contents of this method with the code editor.

            /// </summary>

            private void InitializeComponent()

            {

                  this.changePasswordButton = new System.Windows.Forms.Button();

                  this.oldPasswordTextBox = new System.Windows.Forms.TextBox();

                  this.newPasswordTextBox = new System.Windows.Forms.TextBox();

                  this.confirmPasswordTextBox = new System.Windows.Forms.TextBox();

                  this.oldPasswordLabel = new System.Windows.Forms.Label();

                  this.newPasswordLabel = new System.Windows.Forms.Label();

                  this.confirmPasswordLabel = new System.Windows.Forms.Label();

                  this.passwordMatchProvider = new System.Windows.Forms.ErrorProvider();

                  this.cancelButton = new System.Windows.Forms.Button();

                  this.errorLabel = new System.Windows.Forms.Label();

                  this.SuspendLayout();

                  //

                  // changePasswordButton

                  //

                  this.changePasswordButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));

                  this.changePasswordButton.DialogResult = System.Windows.Forms.DialogResult.OK;

                  this.changePasswordButton.Location = new System.Drawing.Point(312, 56);

                  this.changePasswordButton.Name = "changePasswordButton";

                  this.changePasswordButton.Size = new System.Drawing.Size(112, 24);

                  this.changePasswordButton.TabIndex = 3;

                  this.changePasswordButton.Text = "Change &Password";

                  this.changePasswordButton.Click += new System.EventHandler(this.changePasswordButton_Click);

                  //

                  // oldPasswordTextBox

                  //

                  this.oldPasswordTextBox.Location = new System.Drawing.Point(144, 8);

                  this.oldPasswordTextBox.Name = "oldPasswordTextBox";

                  this.oldPasswordTextBox.PasswordChar = '*';

                  this.oldPasswordTextBox.Size = new System.Drawing.Size(112, 20);

                  this.oldPasswordTextBox.TabIndex = 0;

                  this.oldPasswordTextBox.Text = "";

                  //

                  // newPasswordTextBox

                  //

                  this.newPasswordTextBox.Location = new System.Drawing.Point(144, 40);

                  this.newPasswordTextBox.Name = "newPasswordTextBox";

                  this.newPasswordTextBox.PasswordChar = '*';

                  this.newPasswordTextBox.Size = new System.Drawing.Size(112, 20);

                  this.newPasswordTextBox.TabIndex = 1;

                  this.newPasswordTextBox.Text = "";

                  //

                  // confirmPasswordTextBox

                  //

                  this.confirmPasswordTextBox.Location = new System.Drawing.Point(144, 72);

                  this.confirmPasswordTextBox.Name = "confirmPasswordTextBox";

                  this.confirmPasswordTextBox.PasswordChar = '*';

                  this.confirmPasswordTextBox.Size = new System.Drawing.Size(112, 20);

                  this.confirmPasswordTextBox.TabIndex = 2;

                  this.confirmPasswordTextBox.Text = "";

                  //

                  // oldPasswordLabel

                  //

                  this.oldPasswordLabel.Location = new System.Drawing.Point(8, 8);

                  this.oldPasswordLabel.Name = "oldPasswordLabel";

                  this.oldPasswordLabel.Size = new System.Drawing.Size(128, 20);

                  this.oldPasswordLabel.TabIndex = 4;

                  this.oldPasswordLabel.Text = "Old Password:";

                  this.oldPasswordLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

                  //

                  // newPasswordLabel

                  //

                  this.newPasswordLabel.Location = new System.Drawing.Point(8, 40);

                  this.newPasswordLabel.Name = "newPasswordLabel";

                  this.newPasswordLabel.Size = new System.Drawing.Size(128, 20);

                  this.newPasswordLabel.TabIndex = 5;

                  this.newPasswordLabel.Text = "New Password:";

                  this.newPasswordLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

                  //

                  // confirmPasswordLabel

                  //

                  this.confirmPasswordLabel.Location = new System.Drawing.Point(8, 72);

                  this.confirmPasswordLabel.Name = "confirmPasswordLabel";

                  this.confirmPasswordLabel.Size = new System.Drawing.Size(128, 20);

                  this.confirmPasswordLabel.TabIndex = 6;

                  this.confirmPasswordLabel.Text = "Confirm New Password:";

                  this.confirmPasswordLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

                  //

                  // passwordMatchProvider

                  //

                  this.passwordMatchProvider.ContainerControl = this;

                  //

                  // cancelButton

                  //

                  this.cancelButton.CausesValidation = false;