diff --git a/Crypto Notepad/Forms/ChangeKeyForm.cs b/Crypto Notepad/Forms/ChangeKeyForm.cs index 8484d4f..78d7897 100644 --- a/Crypto Notepad/Forms/ChangeKeyForm.cs +++ b/Crypto Notepad/Forms/ChangeKeyForm.cs @@ -14,40 +14,38 @@ public ChangeKeyForm() statusLabel.Text = ""; } - /*Buttons*/ - private async void AcceptButton_Click(object sender, EventArgs e) + #region Methods + private async void ChangePasswordStatus(string message, Color color) + { + statusLabel.ForeColor = color; + statusLabel.Text = message; + oldKeyTextBox.Text = ""; + newKeyTextBox.Text = ""; + await Task.Delay(2500); + statusLabel.Text = ""; + } + #endregion + + + #region Event Handlers + private void AcceptButton_Click(object sender, EventArgs e) { oldKeyTextBox.Focus(); if (oldKeyTextBox.Text == PublicVar.password.Get() & oldKeyTextBox.Text != newKeyTextBox.Text) { PublicVar.password.Set(newKeyTextBox.Text); PublicVar.passwordChanged = true; - statusLabel.ForeColor = Color.Green; - statusLabel.Text = "Password was successfully changed"; - oldKeyTextBox.Text = ""; - newKeyTextBox.Text = ""; - await Task.Delay(3000); - statusLabel.Text = ""; + ChangePasswordStatus("Password was successfully changed", Color.Green); } else if (oldKeyTextBox.Text != PublicVar.password.Get()) { SystemSounds.Hand.Play(); - statusLabel.ForeColor = Color.Red; - statusLabel.Text = "Invalid old password"; - oldKeyTextBox.Text = ""; - newKeyTextBox.Text = ""; - await Task.Delay(2000); - statusLabel.Text = ""; + ChangePasswordStatus("Invalid old password", Color.Red); } - else if(oldKeyTextBox.Text == newKeyTextBox.Text) + else if (oldKeyTextBox.Text == newKeyTextBox.Text) { SystemSounds.Hand.Play(); - statusLabel.ForeColor = Color.Red; - statusLabel.Text = "New password is the same as old"; - oldKeyTextBox.Text = ""; - newKeyTextBox.Text = ""; - await Task.Delay(2000); - statusLabel.Text = ""; + ChangePasswordStatus("New password is the same as old", Color.Red); } } @@ -60,10 +58,7 @@ private void PasswordGeneratorButton_Click(object sender, EventArgs e) passwordGeneratorFrom.Show(this); } } - /*Buttons*/ - - /*Enter keys area*/ private void ShowOldKeyPictureBox_Click(object sender, EventArgs e) { if (oldKeyTextBox.UseSystemPasswordChar) @@ -148,7 +143,7 @@ private void OldKeyTextBox_KeyDown(object sender, KeyEventArgs e) AcceptButton_Click(sender, e); } } - /*Enter keys area*/ + #endregion }