forked from chieunhatnang/VM-QuickConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForcePasswordChange.cs
104 lines (93 loc) · 3.04 KB
/
ForcePasswordChange.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace LowEndViet.com_VPS_Tool
{
public partial class ForcePasswordChange : Form
{
public string oldPassword { get; set; }
public string newPassword { get; set; }
public ForcePasswordChange()
{
InitializeComponent();
}
private void btnForceChangePassword_Click(object sender, EventArgs e)
{
if (txtNewPassword.Text == txtNewPassword2.Text)
{
submitPassword();
} else
{
MessageBox.Show("NEW Passwords not match!");
}
}
private void txtNewPassword_TextChanged(object sender, EventArgs e)
{
if (isStrongPassword(txtNewPassword.Text))
{
lblPasswordStrength.Text = "Good";
lblPasswordStrength.ForeColor = System.Drawing.Color.Green;
}
else
{
lblPasswordStrength.Text = "Weak";
lblPasswordStrength.ForeColor = System.Drawing.Color.Red;
}
}
protected override CreateParams CreateParams
{
get
{
const int CS_NOCLOSE = 0x200;
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_NOCLOSE;
return cp;
}
}
private void txtNewPassword_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
submitPassword();
}
}
private Boolean isStrongPassword(string password)
{
string[] badPasswordList = null;
try
{
badPasswordList = File.ReadAllText("C:\\Users\\Public\\LEV\\bad_pw.txt").Split(',');
} catch
{
}
if (password.Length >= 8 && (password.Any(char.IsUpper) && password.Any(char.IsLower) && password.Any(char.IsDigit))
&& (badPasswordList == null || !badPasswordList.Contains(password)))
{
return true;
}
else
{
return false;
}
}
private void submitPassword()
{
if (!isStrongPassword(txtNewPassword.Text))
{
MessageBox.Show("Password must be:\r\n- More than 8 characters\r\n- Contains UPPER CASE leters (A-Z)\r\n- Contains lower case letter (a-z)\r\n- Contains number (0-9)");
return;
}
this.oldPassword = txtOldPassword.Text;
this.newPassword = txtNewPassword.Text;
this.DialogResult = DialogResult.OK;
this.Close();
}
}
}