2019-11-19 13:55:05 +00:00
|
|
|
|
using Crypto_Notepad.Properties;
|
|
|
|
|
|
using PasswordGenerator;
|
2019-11-11 17:19:29 +00:00
|
|
|
|
using System;
|
2019-11-19 13:55:05 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2019-11-11 17:19:29 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Crypto_Notepad
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class PasswordGeneratorFrom : Form
|
|
|
|
|
|
{
|
2019-11-19 13:55:05 +00:00
|
|
|
|
Settings settings = Settings.Default;
|
2019-11-11 17:19:29 +00:00
|
|
|
|
public PasswordGeneratorFrom()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-20 11:59:38 +00:00
|
|
|
|
#region Methods
|
2019-11-19 13:55:05 +00:00
|
|
|
|
private IEnumerable<string> GeneratePasswordGroup()
|
|
|
|
|
|
{
|
2019-12-11 14:21:26 +00:00
|
|
|
|
IPassword pwd;
|
|
|
|
|
|
bool includeSpecial = true;
|
|
|
|
|
|
string main = @"/\!?@#&$%№";
|
|
|
|
|
|
string additional = "\";_-.=*+:^,|'";
|
|
|
|
|
|
string brackets = "(){}[]<>";
|
|
|
|
|
|
|
|
|
|
|
|
if (!specialCheckBox.Checked)
|
|
|
|
|
|
{
|
|
|
|
|
|
main = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!additionalCheckBox.Checked)
|
|
|
|
|
|
{
|
|
|
|
|
|
additional = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!bracketsCheckBox.Checked)
|
|
|
|
|
|
{
|
|
|
|
|
|
brackets = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!specialCheckBox.Checked & !additionalCheckBox.Checked & !bracketsCheckBox.Checked)
|
|
|
|
|
|
{
|
|
|
|
|
|
includeSpecial = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (includeSpecial)
|
|
|
|
|
|
{
|
|
|
|
|
|
pwd = new Password(
|
2019-11-19 13:55:05 +00:00
|
|
|
|
includeLowercase: lowercaseCheckBox.Checked,
|
|
|
|
|
|
includeUppercase: uppercaseCheckBox.Checked,
|
|
|
|
|
|
includeNumeric: numericCheckBox.Checked,
|
2019-12-11 14:21:26 +00:00
|
|
|
|
includeSpecial: false,
|
|
|
|
|
|
passwordLength: int.Parse(passwordLengthTextBox.Text)).IncludeSpecial(main + additional + brackets);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
pwd = new Password(
|
|
|
|
|
|
includeLowercase: lowercaseCheckBox.Checked,
|
|
|
|
|
|
includeUppercase: uppercaseCheckBox.Checked,
|
|
|
|
|
|
includeNumeric: numericCheckBox.Checked,
|
|
|
|
|
|
includeSpecial: false,
|
2019-11-19 13:55:05 +00:00
|
|
|
|
passwordLength: int.Parse(passwordLengthTextBox.Text));
|
2019-12-11 14:21:26 +00:00
|
|
|
|
}
|
2019-11-24 07:39:14 +00:00
|
|
|
|
return pwd.NextGroup(Convert.ToInt32(numberOfStringsTextBox.Text));
|
2019-11-19 13:55:05 +00:00
|
|
|
|
}
|
2019-11-20 11:59:38 +00:00
|
|
|
|
#endregion
|
2019-11-19 13:55:05 +00:00
|
|
|
|
|
2019-11-20 11:59:38 +00:00
|
|
|
|
|
|
|
|
|
|
#region Event Handlers
|
2019-11-11 17:19:29 +00:00
|
|
|
|
private void GenerateButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-11-24 07:39:14 +00:00
|
|
|
|
passwordsListTextBox.AppendLine(string.Join(Environment.NewLine, GeneratePasswordGroup().ToArray()));
|
2019-11-11 17:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ClearPasswordsListButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-11-24 07:39:14 +00:00
|
|
|
|
passwordsListTextBox.Clear();
|
2019-11-11 17:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PasswordLengthTextBox_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!char.IsControl(e.KeyChar) & !char.IsDigit(e.KeyChar))
|
|
|
|
|
|
{
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-11 18:54:03 +00:00
|
|
|
|
private void PasswordGeneratorFrom_Load(object sender, EventArgs e)
|
2019-11-11 17:19:29 +00:00
|
|
|
|
{
|
|
|
|
|
|
CenterToParent();
|
2019-11-19 13:55:05 +00:00
|
|
|
|
lowercaseCheckBox.Checked = settings.passwordGeneratorLowercase;
|
|
|
|
|
|
uppercaseCheckBox.Checked = settings.passwordGeneratorUppercase;
|
|
|
|
|
|
numericCheckBox.Checked = settings.passwordGeneratorNumeric;
|
|
|
|
|
|
specialCheckBox.Checked = settings.passwordGeneratorSpecial;
|
2019-12-11 14:21:26 +00:00
|
|
|
|
bracketsCheckBox.Checked = settings.passwordGeneratorBrackets;
|
|
|
|
|
|
additionalCheckBox.Checked = settings.passwordGeneratorAdditional;
|
2019-11-19 13:55:05 +00:00
|
|
|
|
passwordLengthTextBox.Text = settings.passwordGeneratorLength;
|
2019-11-24 07:39:14 +00:00
|
|
|
|
numberOfStringsTextBox.Text = settings.passwordGeneratorNumberOfStrings;
|
|
|
|
|
|
passwordsListTextBox.Text = string.Join(Environment.NewLine, GeneratePasswordGroup().ToArray());
|
2019-11-19 13:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void LowercaseCheckBox_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.passwordGeneratorLowercase = lowercaseCheckBox.Checked;
|
|
|
|
|
|
settings.Save();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UppercaseCheckBox_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.passwordGeneratorUppercase = uppercaseCheckBox.Checked;
|
|
|
|
|
|
settings.Save();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void NumericCheckBox_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.passwordGeneratorNumeric = numericCheckBox.Checked;
|
|
|
|
|
|
settings.Save();
|
2019-11-11 17:19:29 +00:00
|
|
|
|
}
|
2019-11-19 13:55:05 +00:00
|
|
|
|
|
|
|
|
|
|
private void SpecialCheckBox_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.passwordGeneratorSpecial = specialCheckBox.Checked;
|
|
|
|
|
|
settings.Save();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PasswordGeneratorFrom_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!settings.passwordGeneratorLowercase & !settings.passwordGeneratorUppercase
|
|
|
|
|
|
& !settings.passwordGeneratorNumeric & !settings.passwordGeneratorSpecial)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.passwordGeneratorLowercase = true;
|
|
|
|
|
|
}
|
2019-11-24 07:39:14 +00:00
|
|
|
|
try
|
2019-11-19 13:55:05 +00:00
|
|
|
|
{
|
2019-12-11 14:21:41 +00:00
|
|
|
|
if (Enumerable.Range(4, 256).Contains(int.Parse(passwordLengthTextBox.Text)))
|
2019-11-19 13:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
settings.passwordGeneratorLength = passwordLengthTextBox.Text;
|
|
|
|
|
|
}
|
2019-11-24 07:39:14 +00:00
|
|
|
|
if (Enumerable.Range(1, 1000).Contains(int.Parse(numberOfStringsTextBox.Text)))
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.passwordGeneratorNumberOfStrings = numberOfStringsTextBox.Text;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2019-11-19 13:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
settings.Save();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PasswordValidation(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-11-24 07:39:14 +00:00
|
|
|
|
try
|
2019-11-19 13:55:05 +00:00
|
|
|
|
{
|
2019-11-24 07:39:14 +00:00
|
|
|
|
if (!Enumerable.Range(1, 1000).Contains(int.Parse(numberOfStringsTextBox.Text)) |
|
2019-12-11 14:21:41 +00:00
|
|
|
|
!Enumerable.Range(4, 256).Contains(int.Parse(passwordLengthTextBox.Text)) |
|
2019-11-24 07:39:14 +00:00
|
|
|
|
!lowercaseCheckBox.Checked &
|
|
|
|
|
|
!uppercaseCheckBox.Checked &
|
|
|
|
|
|
!numericCheckBox.Checked &
|
2019-12-11 14:21:26 +00:00
|
|
|
|
!specialCheckBox.Checked &
|
|
|
|
|
|
!additionalCheckBox.Checked &
|
|
|
|
|
|
!bracketsCheckBox.Checked |
|
2019-11-24 07:39:14 +00:00
|
|
|
|
string.IsNullOrWhiteSpace(numberOfStringsTextBox.Text.Trim('0')))
|
2019-11-19 13:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
generateButton.Enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
generateButton.Enabled = true;
|
|
|
|
|
|
}
|
2019-11-24 07:39:14 +00:00
|
|
|
|
|
2019-11-19 13:55:05 +00:00
|
|
|
|
}
|
2019-11-24 07:39:14 +00:00
|
|
|
|
catch
|
2019-11-19 13:55:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
generateButton.Enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-24 07:39:14 +00:00
|
|
|
|
|
|
|
|
|
|
private void CopyAllButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Clipboard.SetText(passwordsListTextBox.Text);
|
2019-11-24 20:03:20 +00:00
|
|
|
|
passwordGeneratorToolTip.SetToolTip(copyAllButton, "Copied");
|
2019-11-24 07:39:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CopyLastButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Clipboard.SetText(passwordsListTextBox.Lines[passwordsListTextBox.Lines.Length - 1]);
|
2019-11-24 20:03:20 +00:00
|
|
|
|
passwordGeneratorToolTip.SetToolTip(copyLastButton, "Copied");
|
2019-11-24 07:39:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PasswordsListTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(passwordsListTextBox.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
copyLastButton.Enabled = false;
|
|
|
|
|
|
copyAllButton.Enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
copyLastButton.Enabled = true;
|
|
|
|
|
|
copyAllButton.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-11-24 20:03:20 +00:00
|
|
|
|
|
|
|
|
|
|
private void CopyLastButton_MouseEnter(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-12-11 14:21:26 +00:00
|
|
|
|
passwordGeneratorToolTip.AutoPopDelay = 1000;
|
2019-11-24 20:03:20 +00:00
|
|
|
|
passwordGeneratorToolTip.SetToolTip(copyLastButton, null);
|
|
|
|
|
|
}
|
2019-11-19 13:55:05 +00:00
|
|
|
|
|
2019-11-24 20:03:20 +00:00
|
|
|
|
private void CopyAllButton_MouseEnter(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2019-12-11 14:21:26 +00:00
|
|
|
|
passwordGeneratorToolTip.AutoPopDelay = 1000;
|
2019-11-24 20:03:20 +00:00
|
|
|
|
passwordGeneratorToolTip.SetToolTip(copyAllButton, null);
|
|
|
|
|
|
}
|
2019-11-27 17:22:48 +00:00
|
|
|
|
|
|
|
|
|
|
private void PasswordGeneratorFrom_Deactivate(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
PasswordGeneratorFrom_FormClosing(null, null);
|
|
|
|
|
|
}
|
2019-12-11 14:21:26 +00:00
|
|
|
|
|
2019-11-24 20:06:42 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2019-12-11 14:21:26 +00:00
|
|
|
|
private void SpecialCheckBox_MouseEnter(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
passwordGeneratorToolTip.AutoPopDelay = 10000;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BracketsCheckBox_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.passwordGeneratorBrackets = bracketsCheckBox.Checked;
|
|
|
|
|
|
settings.Save();
|
|
|
|
|
|
}
|
2019-11-24 20:06:42 +00:00
|
|
|
|
|
2019-12-11 14:21:26 +00:00
|
|
|
|
private void additionalCheckBox_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
settings.passwordGeneratorAdditional = additionalCheckBox.Checked;
|
|
|
|
|
|
settings.Save();
|
|
|
|
|
|
}
|
2019-11-11 17:19:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|