using System;
|
using System.Configuration;
|
using System.Windows.Forms;
|
|
namespace Bro.UI.Config
|
{
|
public partial class AdvancedPwdFrm : Form
|
{
|
public static Action<bool> OnLoginOK { get; set; }
|
|
string pwd = "";
|
|
string PWD
|
{
|
get
|
{
|
if (string.IsNullOrWhiteSpace(pwd))
|
{
|
var pwdSetting = ConfigurationManager.AppSettings["Pwd"];
|
|
if (!string.IsNullOrWhiteSpace(pwdSetting))
|
{
|
pwd = pwdSetting.ToString();
|
}
|
else
|
{
|
pwd = "p@ssw0rd";
|
}
|
}
|
|
return pwd;
|
}
|
}
|
|
public AdvancedPwdFrm()
|
{
|
InitializeComponent();
|
}
|
|
private void button1_Click(object sender, EventArgs e)
|
{
|
DialogResult = DialogResult.Cancel;
|
}
|
|
private void button2_Click(object sender, EventArgs e)
|
{
|
CheckInputPassword();
|
}
|
|
private void CheckInputPassword()
|
{
|
string input = txtPwd.Text.Trim();
|
|
if (string.IsNullOrWhiteSpace(input))
|
{
|
MessageBox.Show("Please input password");
|
return;
|
}
|
|
if (input == PWD)
|
{
|
OnLoginOK?.Invoke(true);
|
DialogResult = DialogResult.OK;
|
}
|
else
|
{
|
MessageBox.Show("Wrong Password");
|
DialogResult = DialogResult.Cancel;
|
}
|
}
|
|
private void txtPwd_KeyDown(object sender, KeyEventArgs e)
|
{
|
if (e.KeyCode == Keys.Enter)
|
{
|
CheckInputPassword();
|
}
|
}
|
}
|
}
|