Crypto-Notepad/Crypto Notepad/Forms/ChangePasswordForm.cs

151 lines
4.6 KiB
C#
Raw Permalink Normal View History

using System;
2019-10-13 11:54:45 +00:00
using System.Drawing;
2016-01-25 18:22:58 +00:00
using System.Media;
using System.Threading.Tasks;
2016-01-07 16:45:32 +00:00
using System.Windows.Forms;
2016-01-09 20:46:25 +00:00
namespace Crypto_Notepad
2016-01-07 16:45:32 +00:00
{
public partial class ChangePasswordForm : Form
2016-01-07 16:45:32 +00:00
{
public ChangePasswordForm()
2016-01-07 16:45:32 +00:00
{
InitializeComponent();
2019-10-15 16:48:17 +00:00
statusLabel.Text = "";
2016-01-07 16:45:32 +00:00
}
#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)
2016-01-07 16:45:32 +00:00
{
2019-10-13 11:54:45 +00:00
oldKeyTextBox.Focus();
2019-11-27 09:59:42 +00:00
if (oldKeyTextBox.Text == PublicVar.password.Get() & oldKeyTextBox.Text != newKeyTextBox.Text)
2016-01-07 16:45:32 +00:00
{
2019-11-27 09:59:42 +00:00
PublicVar.password.Set(newKeyTextBox.Text);
PublicVar.passwordChanged = true;
ChangePasswordStatus("Password was successfully changed", Color.Green);
2016-01-07 16:45:32 +00:00
}
2019-11-27 09:59:42 +00:00
else if (oldKeyTextBox.Text != PublicVar.password.Get())
2016-01-07 16:45:32 +00:00
{
SystemSounds.Hand.Play();
ChangePasswordStatus("Invalid old password", Color.Red);
2016-01-22 17:42:13 +00:00
}
else if (oldKeyTextBox.Text == newKeyTextBox.Text)
2016-01-22 17:42:13 +00:00
{
SystemSounds.Hand.Play();
ChangePasswordStatus("New password is the same as old", Color.Red);
2016-01-07 16:45:32 +00:00
}
}
2019-11-11 17:19:29 +00:00
private void PasswordGeneratorButton_Click(object sender, EventArgs e)
{
ActiveControl = null;
PasswordGeneratorFrom passwordGeneratorFrom = new PasswordGeneratorFrom();
if ((Application.OpenForms["PasswordGeneratorFrom"] as PasswordGeneratorFrom) == null)
{
passwordGeneratorFrom.Show(this);
}
}
2019-10-13 11:54:45 +00:00
private void ShowOldKeyPictureBox_Click(object sender, EventArgs e)
2016-01-07 16:45:32 +00:00
{
2019-10-13 11:54:45 +00:00
if (oldKeyTextBox.UseSystemPasswordChar)
2016-01-07 16:45:32 +00:00
{
2019-10-13 11:54:45 +00:00
oldKeyTextBox.UseSystemPasswordChar = false;
showOldKeyPictureBox.Image = Properties.Resources.eye;
2016-01-07 16:45:32 +00:00
}
else
2016-01-07 16:45:32 +00:00
{
2019-10-13 11:54:45 +00:00
oldKeyTextBox.UseSystemPasswordChar = true;
showOldKeyPictureBox.Image = Properties.Resources.eye_half;
2016-01-07 16:45:32 +00:00
}
}
2019-10-13 11:54:45 +00:00
private void ShowNewKeyPictureBox_Click(object sender, EventArgs e)
2016-01-07 16:45:32 +00:00
{
2019-10-13 11:54:45 +00:00
if (newKeyTextBox.UseSystemPasswordChar)
2016-01-07 16:45:32 +00:00
{
2019-10-13 11:54:45 +00:00
newKeyTextBox.UseSystemPasswordChar = false;
showNewKeyPictureBox.Image = Properties.Resources.eye;
2016-01-07 16:45:32 +00:00
}
else
2016-01-07 16:45:32 +00:00
{
2019-10-13 11:54:45 +00:00
newKeyTextBox.UseSystemPasswordChar = true;
showNewKeyPictureBox.Image = Properties.Resources.eye_half;
2016-01-07 16:45:32 +00:00
}
}
2016-01-10 12:29:19 +00:00
2019-10-13 11:54:45 +00:00
private void OldKeyTextBox_TextChanged(object sender, EventArgs e)
{
2019-10-13 11:54:45 +00:00
if (oldKeyTextBox.Text.Length > 0 & newKeyTextBox.Text.Length > 0)
{
acceptButton.Enabled = true;
}
else
{
acceptButton.Enabled = false;
}
}
2019-10-13 11:54:45 +00:00
private void NewKeyTextBox_TextChanged(object sender, EventArgs e)
{
2019-10-13 11:54:45 +00:00
if (newKeyTextBox.Text.Length > 0 & oldKeyTextBox.Text.Length > 0)
{
acceptButton.Enabled = true;
}
else
{
acceptButton.Enabled = false;
}
2019-10-13 11:55:20 +00:00
}
private void NewKeyPlaceholder_Click(object sender, EventArgs e)
{
newKeyTextBox.Focus();
}
private void OldKeyPlaceholder_Click(object sender, EventArgs e)
{
oldKeyTextBox.Focus();
}
2019-10-13 11:54:45 +00:00
private void NewKeyTextBox_KeyDown(object sender, KeyEventArgs e)
{
2019-10-15 16:13:08 +00:00
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
}
2019-10-13 11:54:45 +00:00
if (e.KeyCode == Keys.Enter & acceptButton.Enabled)
{
AcceptButton_Click(sender, e);
}
}
private void OldKeyTextBox_KeyDown(object sender, KeyEventArgs e)
{
2019-10-15 16:13:08 +00:00
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
}
2019-10-13 11:54:45 +00:00
if (e.KeyCode == Keys.Enter & acceptButton.Enabled)
{
AcceptButton_Click(sender, e);
}
}
#endregion
2019-10-13 11:54:45 +00:00
2016-01-07 16:45:32 +00:00
}
}