@@ -4,44 +4,139 @@ namespace PassGen
44{
55 public partial class MainForm : Form
66 {
7- static readonly string AlphabetCapital = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
8- static readonly string AlphabetLower = "abcdefghijklmnopqrstuvwxyz" ;
9- static readonly string AlphabetNumber = "0123456789" ;
10- static readonly string AlphabetLine = "-_" ;
11- static readonly string AlphabetSpecial = "`~!@#$%^&*()+={}[]\\ |:;\" \' <>,.?/" ;
12- static readonly string AlphabetSpace = " " ;
7+ string AlphabetCapital = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
8+ string AlphabetLower = "abcdefghijklmnopqrstuvwxyz" ;
9+ const string AlphabetNumber = "0123456789" ;
10+ const string AlphabetLine = "-_" ;
11+ string AlphabetSpecial = "`~!@#$%^&*()+={}[]\\ |:;\" \' <>,.?/" ;
1312 string Password = string . Empty ;
1413 int PasswordLength = 12 ;
1514
1615 private void GeneratePassword ( )
1716 {
17+ if ( CheckBoxReadable . Checked )
18+ {
19+ AlphabetCapital = "ABCDEFGHJKPQRSTUVWXYZ" ;
20+ AlphabetLower = "abcdefghjkpqrstuvwxyz" ;
21+ AlphabetSpecial = "!@#$%&+=?" ;
22+ }
23+
1824 string alphabet = string . Empty ;
1925 if ( CheckBoxCapital . Checked ) { alphabet += AlphabetCapital ; }
2026 if ( CheckBoxLower . Checked ) { alphabet += AlphabetLower ; }
2127 if ( CheckBoxNumber . Checked ) { alphabet += AlphabetNumber ; }
2228 if ( CheckBoxLine . Checked ) { alphabet += AlphabetLine ; }
2329 if ( CheckBoxSpecial . Checked ) { alphabet += AlphabetSpecial ; }
24- if ( CheckBoxSpace . Checked ) { alphabet += AlphabetSpace ; }
2530
2631 int alphabetSize = alphabet . Length ;
2732 if ( alphabetSize == 0 )
33+ {
34+ FieldPassword . Text = string . Empty ;
2835 return ;
36+ }
2937
3038 Password = string . Empty ;
3139 for ( int i = 0 ; i < PasswordLength ; i ++ )
3240 {
3341 int randomNumber = RandomNumberGenerator . GetInt32 ( 0 , alphabetSize ) ;
34- char randomSymbol = alphabet [ randomNumber ] ;
42+ string randomSymbol = alphabet [ randomNumber ] . ToString ( ) ;
3543 Password += randomSymbol ;
3644 }
3745
46+ if ( CheckBoxForce . Checked )
47+ {
48+ ForceAddition ( ) ;
49+ }
50+
3851 FieldPassword . Text = Password ;
3952 }
4053
54+ private void ForceAddition ( )
55+ {
56+ int checkedCount = 0 ;
57+ if ( CheckBoxCapital . Checked ) { checkedCount ++ ; }
58+ if ( CheckBoxLower . Checked ) { checkedCount ++ ; }
59+ if ( CheckBoxNumber . Checked ) { checkedCount ++ ; }
60+ if ( CheckBoxLine . Checked ) { checkedCount ++ ; }
61+ if ( CheckBoxSpecial . Checked ) { checkedCount ++ ; }
62+
63+ if ( checkedCount > PasswordLength )
64+ {
65+ Password = string . Empty ;
66+ return ;
67+ }
68+
69+ string positions = string . Empty ;
70+ int position = 0 ;
71+ int randomPosition ;
72+ for ( int i = 0 ; i < checkedCount ; i ++ )
73+ {
74+ do
75+ {
76+ randomPosition = RandomNumberGenerator . GetInt32 ( 0 , PasswordLength ) ;
77+ }
78+ while ( positions . Contains ( randomPosition . ToString ( ) ) ) ;
79+ positions += randomPosition ;
80+ }
81+ if ( CheckBoxCapital . Checked )
82+ {
83+ int randomNumber = RandomNumberGenerator . GetInt32 ( 0 , AlphabetCapital . Length ) ;
84+ string randomSymbol = AlphabetCapital [ randomNumber ] . ToString ( ) ;
85+ Password = Password . Remove ( Convert . ToInt32 ( positions [ position ] . ToString ( ) ) , 1 ) ;
86+ Password = Password . Insert ( Convert . ToInt32 ( positions [ position ] . ToString ( ) ) , randomSymbol ) ;
87+ position ++ ;
88+ }
89+ if ( CheckBoxLower . Checked )
90+ {
91+ int randomNumber = RandomNumberGenerator . GetInt32 ( 0 , AlphabetLower . Length ) ;
92+ string randomSymbol = AlphabetLower [ randomNumber ] . ToString ( ) ;
93+ Password = Password . Remove ( Convert . ToInt32 ( positions [ position ] . ToString ( ) ) , 1 ) ;
94+ Password = Password . Insert ( Convert . ToInt32 ( positions [ position ] . ToString ( ) ) , randomSymbol ) ;
95+ position ++ ;
96+ }
97+ if ( CheckBoxNumber . Checked )
98+ {
99+ int randomNumber = RandomNumberGenerator . GetInt32 ( 0 , AlphabetNumber . Length ) ;
100+ string randomSymbol = AlphabetNumber [ randomNumber ] . ToString ( ) ;
101+ Password = Password . Remove ( Convert . ToInt32 ( positions [ position ] . ToString ( ) ) , 1 ) ;
102+ Password = Password . Insert ( Convert . ToInt32 ( positions [ position ] . ToString ( ) ) , randomSymbol ) ;
103+ position ++ ;
104+ }
105+ if ( CheckBoxLine . Checked )
106+ {
107+ int randomNumber = RandomNumberGenerator . GetInt32 ( 0 , AlphabetLine . Length ) ;
108+ string randomSymbol = AlphabetLine [ randomNumber ] . ToString ( ) ;
109+ Password = Password . Remove ( Convert . ToInt32 ( positions [ position ] . ToString ( ) ) , 1 ) ;
110+ Password = Password . Insert ( Convert . ToInt32 ( positions [ position ] . ToString ( ) ) , randomSymbol ) ;
111+ position ++ ;
112+ }
113+ if ( CheckBoxSpecial . Checked )
114+ {
115+ int randomNumber = RandomNumberGenerator . GetInt32 ( 0 , AlphabetSpecial . Length ) ;
116+ string randomSymbol = AlphabetSpecial [ randomNumber ] . ToString ( ) ;
117+ Password = Password . Remove ( Convert . ToInt32 ( positions [ position ] . ToString ( ) ) , 1 ) ;
118+ Password = Password . Insert ( Convert . ToInt32 ( positions [ position ] . ToString ( ) ) , randomSymbol ) ;
119+ position ++ ;
120+ }
121+ }
122+
41123 public MainForm ( )
42124 {
43125 InitializeComponent ( ) ;
44126 GeneratePassword ( ) ;
127+ ToolTip toolTip = new ( ) ;
128+ toolTip . SetToolTip ( CheckBoxLine , "Ñèìâîëû \" -\" è \" _\" " ) ;
129+ toolTip . SetToolTip ( CheckBoxSpecial , "Ðàçíûå ñïåöèàëüíûå ñèìâîëû" ) ;
130+ toolTip . SetToolTip ( CheckBoxNumber , "Âêëþ÷åíèå öèôð â ïàðîëü" ) ;
131+ toolTip . SetToolTip ( CheckBoxLower , "Âêëþ÷åíèå ñòðî÷íûõ áóêâ â ïàðîëü (a-z)" ) ;
132+ toolTip . SetToolTip ( CheckBoxCapital , "Âêëþ÷åíèå çàãëàâíûõ áóêâ â ïàðîëü (A-Z)" ) ;
133+ toolTip . SetToolTip ( CheckBoxForce , " ïàðîëå áóäåò íå ìåíåå îäíîãî ñèìâîëà èç êàæäîé îòìå÷åííîé êàòåãîðèè" ) ;
134+ toolTip . SetToolTip ( CheckBoxReadable , "Â ïàðîëå íå áóäóò ïîïàäàòüñÿ ñèìâîëû, êîòîðûå ëåãêî ñïóòàòü (íàïðèìåð, 0 è O èëè l è I)" ) ;
135+ toolTip . SetToolTip ( ButtonCopy , "Ñêîïèðîâàòü ïàðîëü â áóôåð îáìåíà" ) ;
136+ toolTip . SetToolTip ( SizeBar , "Äâèãàÿ âëåâî è âïðàâî, ìîæíî èçìåíèòü äëèíó ïàðîëÿ" ) ;
137+ toolTip . SetToolTip ( LabelScrollValue , "Òåêóùàÿ äëèíà ïàðîëÿ" ) ;
138+ toolTip . SetToolTip ( ButtonGen , "Ñîçäàòü íîâûé ïàðîëü" ) ;
139+ toolTip . SetToolTip ( FieldPassword , "Ñîçäàííûå ïàðîëè. Åñëè ïîëå ïóñòîå, çíà÷èò âûáðàííûå íàñòðîéêè íå ïîçâîëÿþò ñîçäàòü åãî" ) ;
45140 }
46141
47142 private void ButtonGen_Click ( object sender , EventArgs e )
0 commit comments