Answer to Question #271787 in C# for haffyurur

Question #271787

Create a Windows application that contains two textboxes and three buttons. One of the textboxes and one of the buttons are initially invisible. The first textbox should be used to input a password. The textbox should be masked to some character of your choosing so that the characters entered by the user are not seen on the screen. When the user clicks the first button, the second textbox and button should be displayed with a prompt asking the user to reenter his or her password. Set the focus to the second password textbox. Now, when the user clicks the second button, have the application compare the values entered to make sure they are the same. Display an appropriate message indicating whether they are the same. Once the check is made, display a third button that resets the form


1
Expert's answer
2021-11-26T07:07:33-0500
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace PasswordProject
{
    public partial class frmPasswordProject : Form
    {
        public frmPasswordProject()
        {
            InitializeComponent();
        }
        /// <summary>
        /// When the user clicks the first button, the second TextBox object and button object should be 
        /// displayed with a prompt asking the user to reenter his or her password.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDisplay_Click(object sender, EventArgs e)
        {
            lblReenteredPassword.Visible = true;
            txtReenteredPassword.Visible = true;
            txtReenteredPassword.Focus();
            btnCheck.Visible = true;
        }
        /// <summary>
        ///  Now the user clicks the second button, have the application compare the values
        ///  entered to make sure they are the same. Display an appropriate message indicating whether they are the same.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCheck_Click(object sender, EventArgs e)
        {
            if (txtSecretPassword.Text == txtReenteredPassword.Text)
            {
                MessageBox.Show("The passwords are the same.");
                btnReset.Visible = true;
            }
            else {
                MessageBox.Show("The passwords are NOT the same.");
            }
        }
        /// <summary>
        /// A third button that resets the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReset_Click(object sender, EventArgs e)
        {
            lblReenteredPassword.Visible = false;
            txtReenteredPassword.Visible = false;
            txtSecretPassword.Clear();
            txtReenteredPassword.Clear();
            txtSecretPassword.Focus();
            btnCheck.Visible = false;
            btnReset.Visible = false;
        }
    }
}






namespace PasswordProject
{
    partial class frmPasswordProject
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;


        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }


        #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.label1 = new System.Windows.Forms.Label();
            this.btnCheck = new System.Windows.Forms.Button();
            this.btnDisplay = new System.Windows.Forms.Button();
            this.lblReenteredPassword = new System.Windows.Forms.Label();
            this.txtSecretPassword = new System.Windows.Forms.TextBox();
            this.txtReenteredPassword = new System.Windows.Forms.TextBox();
            this.btnReset = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(11, 17);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(89, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Secret password:";
            // 
            // btnCheck
            // 
            this.btnCheck.Location = new System.Drawing.Point(57, 84);
            this.btnCheck.Name = "btnCheck";
            this.btnCheck.Size = new System.Drawing.Size(75, 23);
            this.btnCheck.TabIndex = 4;
            this.btnCheck.Text = "Check";
            this.btnCheck.UseVisualStyleBackColor = true;
            this.btnCheck.Visible = false;
            this.btnCheck.Click += new System.EventHandler(this.btnCheck_Click);
            // 
            // btnDisplay
            // 
            this.btnDisplay.Location = new System.Drawing.Point(141, 84);
            this.btnDisplay.Name = "btnDisplay";
            this.btnDisplay.Size = new System.Drawing.Size(75, 23);
            this.btnDisplay.TabIndex = 3;
            this.btnDisplay.Text = "Display";
            this.btnDisplay.UseVisualStyleBackColor = true;
            this.btnDisplay.Click += new System.EventHandler(this.btnDisplay_Click);
            // 
            // lblReenteredPassword
            // 
            this.lblReenteredPassword.AutoSize = true;
            this.lblReenteredPassword.Location = new System.Drawing.Point(11, 49);
            this.lblReenteredPassword.Name = "lblReenteredPassword";
            this.lblReenteredPassword.Size = new System.Drawing.Size(96, 13);
            this.lblReenteredPassword.TabIndex = 3;
            this.lblReenteredPassword.Text = "Reenter password:";
            this.lblReenteredPassword.Visible = false;
            // 
            // txtSecretPassword
            // 
            this.txtSecretPassword.Location = new System.Drawing.Point(116, 14);
            this.txtSecretPassword.Name = "txtSecretPassword";
            this.txtSecretPassword.PasswordChar = '*';
            this.txtSecretPassword.Size = new System.Drawing.Size(100, 20);
            this.txtSecretPassword.TabIndex = 1;
            this.txtSecretPassword.UseSystemPasswordChar = true;
            // 
            // txtReenteredPassword
            // 
            this.txtReenteredPassword.Location = new System.Drawing.Point(116, 46);
            this.txtReenteredPassword.Name = "txtReenteredPassword";
            this.txtReenteredPassword.Size = new System.Drawing.Size(100, 20);
            this.txtReenteredPassword.TabIndex = 2;
            this.txtReenteredPassword.Visible = false;
            // 
            // btnReset
            // 
            this.btnReset.Location = new System.Drawing.Point(57, 113);
            this.btnReset.Name = "btnReset";
            this.btnReset.Size = new System.Drawing.Size(159, 23);
            this.btnReset.TabIndex = 4;
            this.btnReset.Text = "Reset";
            this.btnReset.UseVisualStyleBackColor = true;
            this.btnReset.Visible = false;
            this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
            // 
            // frmPasswordProject
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(242, 150);
            this.Controls.Add(this.txtReenteredPassword);
            this.Controls.Add(this.txtSecretPassword);
            this.Controls.Add(this.lblReenteredPassword);
            this.Controls.Add(this.btnDisplay);
            this.Controls.Add(this.btnReset);
            this.Controls.Add(this.btnCheck);
            this.Controls.Add(this.label1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmPasswordProject";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Password project";
            this.ResumeLayout(false);
            this.PerformLayout();


        }


        #endregion


        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button btnCheck;
        private System.Windows.Forms.Button btnDisplay;
        private System.Windows.Forms.Label lblReenteredPassword;
        private System.Windows.Forms.TextBox txtSecretPassword;
        private System.Windows.Forms.TextBox txtReenteredPassword;
        private System.Windows.Forms.Button btnReset;
    }
}






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS