Crypto-Notepad/Crypto Notepad/ChangeKeyForm.cs

110 lines
3.1 KiB
C#
Raw Normal View History

2016-01-07 16:45:32 +00:00
using System;
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();
}
/*Buttons*/
2019-10-11 10:39:15 +00:00
private async void BtnAccept_Click(object sender, EventArgs e)
2016-01-07 16:45:32 +00:00
{
2019-10-11 10:39:15 +00:00
if (txtOldKey.Text == PublicVar.encryptionKey.Get() && txtOldKey.Text != txtNewKey.Text)
2016-01-07 16:45:32 +00:00
{
2019-10-11 10:39:15 +00:00
PublicVar.encryptionKey.Set(txtNewKey.Text);
2018-12-17 11:04:26 +00:00
PublicVar.keyChanged = true;
2019-10-11 10:39:15 +00:00
txtOldKey.Text = "";
txtNewKey.Text = "";
lblStatus.Text = "Key was successfully changed";
lblStatus.Visible = true;
btnAccept.Enabled = false;
await Task.Delay(2000);
2019-10-11 10:39:15 +00:00
lblStatus.Text = "";
2016-01-22 19:41:31 +00:00
return;
2016-01-07 16:45:32 +00:00
}
2019-10-11 10:39:15 +00:00
if (txtOldKey.Text != PublicVar.encryptionKey.Get())
2016-01-07 16:45:32 +00:00
{
2016-01-25 18:22:58 +00:00
SystemSounds.Beep.Play();
2019-10-11 10:39:15 +00:00
lblStatus.Text = "Invalid old key";
lblStatus.Visible = true;
txtOldKey.Text = "";
txtNewKey.Text = "";
2016-01-22 17:42:13 +00:00
return;
}
2019-10-11 10:39:15 +00:00
if (txtOldKey.Text == txtNewKey.Text)
2016-01-22 17:42:13 +00:00
{
2016-01-25 18:22:58 +00:00
SystemSounds.Beep.Play();
2019-10-11 10:39:15 +00:00
lblStatus.Text = "New key is the same as old";
lblStatus.Visible = true;
txtOldKey.Text = "";
txtNewKey.Text = "";
2016-01-22 17:42:13 +00:00
return;
2016-01-07 16:45:32 +00:00
}
}
/*Buttons*/
2016-01-07 16:45:32 +00:00
/*Enter keys area*/
2019-10-11 10:39:15 +00:00
private void PicOldKeyEyeIcon_Click(object sender, EventArgs e)
2016-01-07 16:45:32 +00:00
{
2019-10-11 10:39:15 +00:00
if (txtOldKey.UseSystemPasswordChar)
2016-01-07 16:45:32 +00:00
{
2019-10-11 10:39:15 +00:00
txtOldKey.UseSystemPasswordChar = false;
picOldKey.Image = Properties.Resources.eye;
2016-01-07 16:45:32 +00:00
}
else
2016-01-07 16:45:32 +00:00
{
2019-10-11 10:39:15 +00:00
txtOldKey.UseSystemPasswordChar = true;
picOldKey.Image = Properties.Resources.eye_half;
2016-01-07 16:45:32 +00:00
}
}
2019-10-11 10:39:15 +00:00
private void PicNewKeyEyeIcon_Click(object sender, EventArgs e)
2016-01-07 16:45:32 +00:00
{
2019-10-11 10:39:15 +00:00
if (txtNewKey.UseSystemPasswordChar)
2016-01-07 16:45:32 +00:00
{
2019-10-11 10:39:15 +00:00
txtNewKey.UseSystemPasswordChar = false;
picNewKey.Image = Properties.Resources.eye;
2016-01-07 16:45:32 +00:00
}
else
2016-01-07 16:45:32 +00:00
{
2019-10-11 10:39:15 +00:00
txtNewKey.UseSystemPasswordChar = true;
picNewKey.Image = Properties.Resources.eye_half;
2016-01-07 16:45:32 +00:00
}
}
2016-01-10 12:29:19 +00:00
2019-10-11 10:39:15 +00:00
private void TxtOldKey_TextChanged(object sender, EventArgs e)
{
2019-10-11 10:39:15 +00:00
if (txtOldKey.Text.Length > 0 && txtNewKey.Text.Length > 0)
{
2019-10-11 10:39:15 +00:00
btnAccept.Enabled = true;
}
else
{
2019-10-11 10:39:15 +00:00
btnAccept.Enabled = false;
}
}
2019-10-11 10:39:15 +00:00
private void TxtNewKey_TextChanged(object sender, EventArgs e)
{
2019-10-11 10:39:15 +00:00
if (txtNewKey.Text.Length > 0 && txtOldKey.Text.Length > 0)
{
2019-10-11 10:39:15 +00:00
btnAccept.Enabled = true;
}
else
{
2019-10-11 10:39:15 +00:00
btnAccept.Enabled = false;
}
}
/*Enter keys area*/
2016-01-07 16:45:32 +00:00
}
}