In: Computer Science
Create a windows application that contains two TextBox objects and two Button objects. One of the TextBox objects 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 choice so that the characters entered by the user are not seen on the screen. 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. 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.
Hi,
Please find the below code and screenshot:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NestedLoop
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
/// <summary>
/// First Button which is displaying when Form Loads
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//when user click this button then Visisble other Button and Text box
txtNormalPass.Visible = true;
button2.Visible = true;
//show Pop up message to user to re enter the password
MessageBox.Show("Re Enter the Password.");
//Clears the Text Value
txtNormalPass.Text = string.Empty;
}
/// <summary>
/// This will all when Form loads into the memory
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form2_Load(object sender, EventArgs e)
{
//Clears the text Values and also hide the Text and Button when form loads
txtNormalPass.Text = string.Empty;
txtNormalPass.Visible = false;
button2.Visible = false;
}
/// <summary>
/// This will check that Users Enters valid pass or not
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
//Fetch Passwords
string sPassword = txtPassword.Text.Trim();
string sMatchPassword = txtNormalPass.Text.Trim();
//Check the Passwords and accordingly show the Popup message
if (sPassword == sMatchPassword)
{
MessageBox.Show("Password Matched");
}
else {
txtNormalPass.Text = string.Empty;
MessageBox.Show("Invalid Password. Please Re-Enter the valid Password");
}
}
}
}
When we run this Windows Form Project, then
When user clicks on the - Show Controls Button
Enters the password which should be same one entered in the first text box
When clicks on the button - Check Password
In case of InValid Password
In Case of Valid Password
Thanks.