Crypto-Notepad/Crypto Notepad/ChangeKeyForm.cs

169 lines
5.1 KiB
C#
Raw 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 ChangeKeyForm : Form
{
public ChangeKeyForm()
{
InitializeComponent();
2019-10-15 16:48:17 +00:00
statusLabel.Text = "";
2016-01-07 16:45:32 +00:00
}
/*Buttons*/
2019-10-13 11:54:45 +00:00
private async 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-10-15 16:48:17 +00:00
if (oldKeyTextBox.Text == PublicVar.encryptionKey.Get() & oldKeyTextBox.Text != newKeyTextBox.Text)
2016-01-07 16:45:32 +00:00
{
2019-10-13 11:54:45 +00:00
PublicVar.encryptionKey.Set(newKeyTextBox.Text);
2018-12-17 11:04:26 +00:00
PublicVar.keyChanged = true;
2019-10-13 11:54:45 +00:00
statusLabel.ForeColor = Color.Green;
statusLabel.Text = "Key was successfully changed";
2019-10-15 16:48:17 +00:00
oldKeyTextBox.Text = "";
newKeyTextBox.Text = "";
await Task.Delay(3000);
2019-10-13 11:54:45 +00:00
statusLabel.Text = "";
2016-01-07 16:45:32 +00:00
}
2019-10-13 11:54:45 +00:00
else if (oldKeyTextBox.Text != PublicVar.encryptionKey.Get())
2016-01-07 16:45:32 +00:00
{
SystemSounds.Hand.Play();
2019-10-13 11:54:45 +00:00
statusLabel.ForeColor = Color.Red;
statusLabel.Text = "Invalid old key";
oldKeyTextBox.Text = "";
newKeyTextBox.Text = "";
await Task.Delay(2000);
statusLabel.Text = "";
2016-01-22 17:42:13 +00:00
}
2019-10-13 11:54:45 +00:00
else if(oldKeyTextBox.Text == newKeyTextBox.Text)
2016-01-22 17:42:13 +00:00
{
SystemSounds.Hand.Play();
2019-10-13 11:54:45 +00:00
statusLabel.ForeColor = Color.Red;
statusLabel.Text = "New key is the same as old";
oldKeyTextBox.Text = "";
newKeyTextBox.Text = "";
await Task.Delay(2000);
statusLabel.Text = "";
2016-01-07 16:45:32 +00:00
}
}
/*Buttons*/
2016-01-07 16:45:32 +00:00
/*Enter keys area*/
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:55:20 +00:00
if (oldKeyTextBox.Text.Length > 0)
{
2019-10-13 11:55:20 +00:00
oldKeyPlaceholder.Visible = false;
}
else
{
2019-10-13 11:55:20 +00:00
oldKeyPlaceholder.Visible = true;
}
}
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;
}
if (newKeyTextBox.Text.Length > 0)
{
2019-10-13 11:55:20 +00:00
newKeyPlaceholder.Visible = false;
}
else
{
2019-10-13 11:55:20 +00:00
newKeyPlaceholder.Visible = true;
}
}
private void NewKeyPlaceholder_Click(object sender, EventArgs e)
{
newKeyTextBox.Focus();
}
private void OldKeyPlaceholder_Click(object sender, EventArgs e)
{
oldKeyTextBox.Focus();
}
private void NewKeyTextBox_Leave(object sender, EventArgs e)
{
if (newKeyTextBox.Text.Length == 0)
{
newKeyPlaceholder.Visible = true;
}
}
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);
}
}
/*Enter keys area*/
2019-10-13 11:54:45 +00:00
2016-01-07 16:45:32 +00:00
}
}