2019-10-15 18:00:19 +00:00
|
|
|
|
using System;
|
2019-10-13 11:54:45 +00:00
|
|
|
|
using System.Drawing;
|
2016-01-25 18:22:58 +00:00
|
|
|
|
using System.Media;
|
2016-01-25 12:49:40 +00:00
|
|
|
|
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
|
|
|
|
{
|
2019-11-28 20:36:49 +00:00
|
|
|
|
public partial class ChangePasswordForm : Form
|
2016-01-07 16:45:32 +00:00
|
|
|
|
{
|
2019-11-28 20:36:49 +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
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-27 14:31:23 +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;
|
2019-11-27 14:31:23 +00:00
|
|
|
|
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
|
|
|
|
{
|
2019-10-15 17:02:10 +00:00
|
|
|
|
SystemSounds.Hand.Play();
|
2019-11-27 14:31:23 +00:00
|
|
|
|
ChangePasswordStatus("Invalid old password", Color.Red);
|
2016-01-22 17:42:13 +00:00
|
|
|
|
}
|
2019-11-27 14:31:23 +00:00
|
|
|
|
else if (oldKeyTextBox.Text == newKeyTextBox.Text)
|
2016-01-22 17:42:13 +00:00
|
|
|
|
{
|
2019-10-15 17:02:10 +00:00
|
|
|
|
SystemSounds.Hand.Play();
|
2019-11-27 14:31:23 +00:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-25 15:55:15 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
2018-12-25 15:55:15 +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
|
|
|
|
}
|
2018-12-25 15:55:15 +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)
|
2016-01-20 19:24:04 +00:00
|
|
|
|
{
|
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-28 18:32:13 +00:00
|
|
|
|
}
|
2016-01-20 19:24:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-13 11:54:45 +00:00
|
|
|
|
private void NewKeyTextBox_TextChanged(object sender, EventArgs e)
|
2016-01-20 19:24:04 +00:00
|
|
|
|
{
|
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-28 18:32:13 +00:00
|
|
|
|
}
|
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);
|
2016-01-20 19:24:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-27 14:31:23 +00:00
|
|
|
|
#endregion
|
2019-10-13 11:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-01-07 16:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|