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;

// Set the TextBox's PasswordChar property to X or something at design time.

namespace PasswordDialog
{
    public partial class PasswordDialog : Form
    {
        public PasswordDialog()
        {
            InitializeComponent();
        }

        // Set the TextBox's PasswordChar property.
        private void PasswordDialog_Load(object sender, EventArgs e)
        {
            passwordTextBox.PasswordChar = 'X';
        }

        // Validate the password.
        private void okButton_Click(object sender, EventArgs e)
        {
            if (passwordTextBox.Text == "Secret")
            {
                // The password is ok.
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                // The password is invalid.
                MessageBox.Show("Invalid password.");
                passwordTextBox.Clear();
                passwordTextBox.Focus();
            }
        }
    }
}
