using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace QC.QTMSecurity;

public class PasswordLoginScreen : Form
{
	private PictureBox pictureBox1;

	private Label lblOldPass;

	private Label lblNewPass;

	private Button btnOk;

	private Button btnCancel;

	private ErrorProvider errorProvider;

	private StatusBar statusBar;

	private TextBox txtOldPass;

	private TextBox txtNewPass;

	private HelpProvider helpProvider;

	private Label lblFailed;

	private Label lblConfirm;

	private TextBox txtConfirmPass;

	private IContainer components;

	private bool changePass;

	public PasswordLoginScreen(bool changingPassword)
	{
		InitializeComponent();
		statusBar.Text = DateTime.Now.ToLongDateString() + "   (" + DateTime.Now.ToLongTimeString() + ")";
		changePass = changingPassword;
		if (changingPassword)
		{
			lblOldPass.Text = "Old password:";
			lblNewPass.Visible = true;
			txtNewPass.Visible = true;
			lblConfirm.Visible = true;
			txtConfirmPass.Visible = true;
		}
		else
		{
			lblOldPass.Text = "Enter password:";
			lblNewPass.Visible = false;
			txtNewPass.Visible = false;
			lblConfirm.Visible = false;
			txtConfirmPass.Visible = false;
		}
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.components = new System.ComponentModel.Container();
		System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(QC.QTMSecurity.PasswordLoginScreen));
		this.pictureBox1 = new System.Windows.Forms.PictureBox();
		this.txtOldPass = new System.Windows.Forms.TextBox();
		this.txtNewPass = new System.Windows.Forms.TextBox();
		this.lblOldPass = new System.Windows.Forms.Label();
		this.lblNewPass = new System.Windows.Forms.Label();
		this.btnOk = new System.Windows.Forms.Button();
		this.btnCancel = new System.Windows.Forms.Button();
		this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
		this.statusBar = new System.Windows.Forms.StatusBar();
		this.helpProvider = new System.Windows.Forms.HelpProvider();
		this.txtConfirmPass = new System.Windows.Forms.TextBox();
		this.lblFailed = new System.Windows.Forms.Label();
		this.lblConfirm = new System.Windows.Forms.Label();
		((System.ComponentModel.ISupportInitialize)this.pictureBox1).BeginInit();
		((System.ComponentModel.ISupportInitialize)this.errorProvider).BeginInit();
		base.SuspendLayout();
		this.pictureBox1.Image = (System.Drawing.Image)resources.GetObject("pictureBox1.Image");
		this.pictureBox1.Location = new System.Drawing.Point(0, 0);
		this.pictureBox1.Name = "pictureBox1";
		this.pictureBox1.Size = new System.Drawing.Size(320, 64);
		this.pictureBox1.TabIndex = 0;
		this.pictureBox1.TabStop = false;
		this.txtOldPass.CausesValidation = false;
		this.helpProvider.SetHelpString(this.txtOldPass, "Provides a space for you to type the current password.");
		this.txtOldPass.Location = new System.Drawing.Point(111, 85);
		this.txtOldPass.Name = "txtOldPass";
		this.txtOldPass.PasswordChar = '*';
		this.helpProvider.SetShowHelp(this.txtOldPass, true);
		this.txtOldPass.Size = new System.Drawing.Size(186, 20);
		this.txtOldPass.TabIndex = 1;
		this.helpProvider.SetHelpString(this.txtNewPass, "Provides a space for you to type the new password.");
		this.txtNewPass.ImeMode = System.Windows.Forms.ImeMode.On;
		this.txtNewPass.Location = new System.Drawing.Point(111, 118);
		this.txtNewPass.Name = "txtNewPass";
		this.txtNewPass.PasswordChar = '*';
		this.helpProvider.SetShowHelp(this.txtNewPass, true);
		this.txtNewPass.Size = new System.Drawing.Size(186, 20);
		this.txtNewPass.TabIndex = 2;
		this.lblOldPass.AutoSize = true;
		this.lblOldPass.Location = new System.Drawing.Point(12, 88);
		this.lblOldPass.Name = "lblOldPass";
		this.lblOldPass.Size = new System.Drawing.Size(75, 13);
		this.lblOldPass.TabIndex = 0;
		this.lblOldPass.Text = "Old Password:";
		this.lblNewPass.AutoSize = true;
		this.lblNewPass.Location = new System.Drawing.Point(12, 121);
		this.lblNewPass.Name = "lblNewPass";
		this.lblNewPass.Size = new System.Drawing.Size(81, 13);
		this.lblNewPass.TabIndex = 2;
		this.lblNewPass.Text = "New Password:";
		this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
		this.btnOk.Location = new System.Drawing.Point(136, 217);
		this.btnOk.Name = "btnOk";
		this.btnOk.Size = new System.Drawing.Size(75, 23);
		this.btnOk.TabIndex = 4;
		this.btnOk.Text = "Ok";
		this.btnOk.Click += new System.EventHandler(btnOk_Click);
		this.btnCancel.CausesValidation = false;
		this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
		this.btnCancel.Location = new System.Drawing.Point(224, 217);
		this.btnCancel.Name = "btnCancel";
		this.btnCancel.Size = new System.Drawing.Size(75, 23);
		this.btnCancel.TabIndex = 5;
		this.btnCancel.Text = "Cancel";
		this.errorProvider.ContainerControl = this;
		this.statusBar.Location = new System.Drawing.Point(0, 246);
		this.statusBar.Name = "statusBar";
		this.statusBar.Size = new System.Drawing.Size(312, 22);
		this.statusBar.TabIndex = 9;
		this.helpProvider.SetHelpString(this.txtConfirmPass, "Provides a space for you to confirm the new password.");
		this.txtConfirmPass.ImeMode = System.Windows.Forms.ImeMode.On;
		this.txtConfirmPass.Location = new System.Drawing.Point(111, 151);
		this.txtConfirmPass.Name = "txtConfirmPass";
		this.txtConfirmPass.PasswordChar = '*';
		this.helpProvider.SetShowHelp(this.txtConfirmPass, true);
		this.txtConfirmPass.Size = new System.Drawing.Size(186, 20);
		this.txtConfirmPass.TabIndex = 3;
		this.lblFailed.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
		this.lblFailed.ForeColor = System.Drawing.Color.FromArgb(192, 0, 0);
		this.lblFailed.Location = new System.Drawing.Point(100, 187);
		this.lblFailed.Name = "lblFailed";
		this.lblFailed.Size = new System.Drawing.Size(112, 23);
		this.lblFailed.TabIndex = 8;
		this.lblFailed.Text = "LOGIN FAILED!";
		this.lblFailed.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
		this.lblFailed.Visible = false;
		this.lblConfirm.AutoSize = true;
		this.lblConfirm.Location = new System.Drawing.Point(12, 154);
		this.lblConfirm.Name = "lblConfirm";
		this.lblConfirm.Size = new System.Drawing.Size(45, 13);
		this.lblConfirm.TabIndex = 4;
		this.lblConfirm.Text = "Confirm:";
		base.AcceptButton = this.btnOk;
		this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
		base.CancelButton = this.btnCancel;
		base.CausesValidation = false;
		base.ClientSize = new System.Drawing.Size(312, 268);
		base.Controls.Add(this.txtConfirmPass);
		base.Controls.Add(this.lblConfirm);
		base.Controls.Add(this.lblFailed);
		base.Controls.Add(this.statusBar);
		base.Controls.Add(this.btnCancel);
		base.Controls.Add(this.btnOk);
		base.Controls.Add(this.lblNewPass);
		base.Controls.Add(this.lblOldPass);
		base.Controls.Add(this.txtNewPass);
		base.Controls.Add(this.txtOldPass);
		base.Controls.Add(this.pictureBox1);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
		base.HelpButton = true;
		base.Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon");
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "PasswordLoginScreen";
		base.ShowInTaskbar = false;
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
		this.Text = "Login ";
		base.Load += new System.EventHandler(LoginScreen_Load);
		((System.ComponentModel.ISupportInitialize)this.pictureBox1).EndInit();
		((System.ComponentModel.ISupportInitialize)this.errorProvider).EndInit();
		base.ResumeLayout(false);
		base.PerformLayout();
	}

	private void btnOk_Click(object sender, EventArgs e)
	{
		errorProvider.SetError(txtOldPass, "");
		if (changePass && txtNewPass.Text.Trim().Length == 0)
		{
			errorProvider.SetError(txtNewPass, "Password cannot be empty.");
			txtNewPass.Focus();
			base.DialogResult = DialogResult.None;
			return;
		}
		errorProvider.SetError(txtNewPass, "");
		if (changePass && txtConfirmPass.Text.Trim().Length == 0)
		{
			errorProvider.SetError(txtConfirmPass, "Password cannot be empty.");
			txtConfirmPass.Focus();
			base.DialogResult = DialogResult.None;
			return;
		}
		errorProvider.SetError(txtConfirmPass, "");
		if (changePass)
		{
			if (!QSecurity.ChangePassword(txtOldPass.Text.Trim(), txtNewPass.Text.Trim(), txtConfirmPass.Text.Trim()))
			{
				lblFailed.Visible = true;
				base.DialogResult = DialogResult.None;
			}
		}
		else if (!QSecurity.PasswordLogin(txtOldPass.Text.Trim()))
		{
			lblFailed.Visible = true;
			base.DialogResult = DialogResult.None;
		}
	}

	private void LoginScreen_Load(object sender, EventArgs e)
	{
	}
}
