From ec0338bb3051a1106ced0b4f10799f1514b40d80 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Tue, 14 Feb 2017 10:36:22 -0700 Subject: [PATCH] fixed small bug with the PasswordForm when it gets loaded multiple times --- mRemoteV1/UI/Forms/PasswordForm.Designer.cs | 9 +++++---- mRemoteV1/UI/Forms/PasswordForm.cs | 20 +++++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/mRemoteV1/UI/Forms/PasswordForm.Designer.cs b/mRemoteV1/UI/Forms/PasswordForm.Designer.cs index 27fede778..7f0a19ad9 100644 --- a/mRemoteV1/UI/Forms/PasswordForm.Designer.cs +++ b/mRemoteV1/UI/Forms/PasswordForm.Designer.cs @@ -38,8 +38,8 @@ namespace mRemoteNG.UI.Forms this.btnCancel = new System.Windows.Forms.Button(); this.lblStatus = new System.Windows.Forms.Label(); this.pbLock = new System.Windows.Forms.PictureBox(); - this.txtVerify = new TextBox(); - this.txtPassword = new TextBox(); + this.txtVerify = new mRemoteNG.UI.Forms.TextBox(); + this.txtPassword = new mRemoteNG.UI.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.pbLock)).BeginInit(); this.SuspendLayout(); // @@ -48,7 +48,7 @@ namespace mRemoteNG.UI.Forms this.lblPassword.AutoSize = true; this.lblPassword.Location = new System.Drawing.Point(82, 12); this.lblPassword.Name = "lblPassword"; - this.lblPassword.Size = new System.Drawing.Size(64, 15); + this.lblPassword.Size = new System.Drawing.Size(56, 13); this.lblPassword.TabIndex = 1; this.lblPassword.Text = "Password:"; // @@ -57,7 +57,7 @@ namespace mRemoteNG.UI.Forms this.lblVerify.AutoSize = true; this.lblVerify.Location = new System.Drawing.Point(82, 51); this.lblVerify.Name = "lblVerify"; - this.lblVerify.Size = new System.Drawing.Size(39, 15); + this.lblVerify.Size = new System.Drawing.Size(36, 13); this.lblVerify.TabIndex = 3; this.lblVerify.Text = "Verify:"; // @@ -155,6 +155,7 @@ namespace mRemoteNG.UI.Forms this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Password"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.PasswordForm_FormClosed); this.Load += new System.EventHandler(this.frmPassword_Load); ((System.ComponentModel.ISupportInitialize)(this.pbLock)).EndInit(); this.ResumeLayout(false); diff --git a/mRemoteV1/UI/Forms/PasswordForm.cs b/mRemoteV1/UI/Forms/PasswordForm.cs index e871025a8..05c7f9d1c 100644 --- a/mRemoteV1/UI/Forms/PasswordForm.cs +++ b/mRemoteV1/UI/Forms/PasswordForm.cs @@ -9,6 +9,7 @@ namespace mRemoteNG.UI.Forms public partial class PasswordForm : IPasswordRequestor { private readonly string _passwordName; + private SecureString _password = new SecureString(); private bool Verify { get; } @@ -22,9 +23,9 @@ namespace mRemoteNG.UI.Forms public SecureString RequestPassword() { var dialog = ShowDialog(); - return dialog == DialogResult.OK ? - (Verify ? txtVerify.Text : txtPassword.Text).ConvertToSecureString() : - new SecureString(); + return dialog == DialogResult.OK + ? _password + : new SecureString(); } #region Event Handlers @@ -38,7 +39,16 @@ namespace mRemoteNG.UI.Forms txtVerify.Visible = false; } - private void btnCancel_Click(object sender, EventArgs e) + private void PasswordForm_FormClosed(object sender, FormClosedEventArgs e) + { + _password = txtPassword.Text.ConvertToSecureString(); + txtPassword.Text = ""; + txtVerify.Text = ""; + if (Verify) return; + Height = Height + (txtVerify.Top - txtPassword.Top); + } + + private void btnCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); @@ -93,5 +103,5 @@ namespace mRemoteNG.UI.Forms lblStatus.Visible = false; } #endregion - } + } } \ No newline at end of file