-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassgen-console.py
executable file
·237 lines (185 loc) · 6.12 KB
/
passgen-console.py
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env python3
# --------------------------------------------------------------------------- #
# #
# Password Generator #
# Copyright (C) diSabler <[email protected]> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
# --------------------------------------------------------------------------- #
import random
import sys
# --------------------------------------------------------------------------- #
# Easy password settings
default_easy_size = 8
min_easy_size = 6
max_easy_size = 32
# Medium password settings
default_medium_size = 8
min_medium_size = 6
max_medium_size = 32
# Strong password settings
default_strong_size = 12
min_strong_size = 6
max_strong_size = 32
# --------------------------------------------------------------------------- #
usage = '''
Generate password:
-e, --easy ... For typing by hand.
-m, --medium . Contain chars, CHARS, numbers. Excluded similar by writing i, l, o, I, L, O, 1, 0.
-s, --strong . Contain chars, CHARS, numbers, symbols. Excluded similar by writing i, l, o, I, L, O, 1, 0.
-t, --turn ... Turn layout EN-RU and RU-EN. Easy for remember, hard for guess.
-a, --about .. About me.
-h, --help ... This text.
Usage:
passgen [type] [password len]
Example:
passgen --easy 10 -e 14 --medium --strong
'''
about = '''
written by diSabler [Andy P. Gorelow]
mail: ..... [email protected]
site: ..... https://dsy.name
telegram: . https://t.me/disabler
(c) Disabler Production Lab.
'''
# --------------------------------------------------------------------------- #
def validate_passwd_length(current_len, default, min_size, max_size):
'''
Validate passwd type and length
'''
if current_len and current_len.isdigit():
current_len = int(current_len)
else:
current_len = default
if current_len < min_size:
current_len = min_size
elif current_len > max_size:
current_len = max_size
return current_len
def shuffle_chars(passwd):
'''
Shuffle password chars
'''
result = ''
while passwd:
result += passwd.pop(random.choice(range(0, len(passwd))))
return result
def select_chars(chars, length):
'''
Select from chars list or lists
'''
result = []
for idx in range(0, length):
result.append(random.choice(chars[idx % len(chars)]))
return result
def gen_chars(_from, _to, exclude = ''):
'''
Generate chars list with exclude
'''
return [chr(t) for t in range(ord(_from), ord(_to) + 1) if chr(t) not in exclude]
def get_passwd_simple(length):
'''
Simple password
'''
length = validate_passwd_length(length, default_easy_size, min_easy_size, max_easy_size)
chars1 = list('aeiou')
chars2 = gen_chars('a', 'z', chars1)
result = ''
begin = random.randint(0,1)
for idx in range(0, length):
if idx % 2 == begin:
char = random.choice(chars2)
if length <= 20:
chars2.remove(char)
else:
char = random.choice(chars1)
if length <= 10:
chars1.remove(char)
result += char
return result
def get_passwd_medium(length):
'''
Medium password
'''
length = validate_passwd_length(length, default_medium_size, min_medium_size, max_medium_size)
chars = [
gen_chars('a', 'z', 'ilo'),
gen_chars('A', 'Z', 'ILO'),
gen_chars('2', '9'),
]
result = select_chars(chars, length)
return shuffle_chars(result)
def get_passwd_strong(length):
'''
Strong password
'''
length = validate_passwd_length(length, default_strong_size, min_strong_size, max_strong_size)
chars = [
gen_chars('a', 'z', 'ilo'),
gen_chars('A', 'Z', 'ILO'),
gen_chars('2', '9'),
list('!@$%^&*'),
]
result = select_chars(chars, length)
return shuffle_chars(result)
def get_passwd_turn(source):
'''
Turn password EN-RU and RU-EN
'''
chars1 = '''`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?'''
chars2 = '''ё1234567890-=йцукенгшщзхъ\фывапролджэячсмитьбю.Ё!"№;%:?*()_+ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,'''
turn1 = chars1 + chars2
turn2 = chars2 + chars1
result = ''.join([turn1[turn2.find(x)] if x in turn2 else x for x in source])
return f'{source} = {result}'
def usage():
'''
Show usage
'''
return usage
def about():
'''
Show about me
'''
return about
# --------------------------------------------------------------------------- #
OPTS = {
'-e': [get_passwd_simple, 1],
'--easy': [get_passwd_simple, 1],
'-m': [get_passwd_medium, 1],
'--medium': [get_passwd_medium, 1],
'-s': [get_passwd_strong, 1],
'--strong': [get_passwd_strong, 1],
'-t': [get_passwd_turn, 1],
'--turn': [get_passwd_turn, 1],
'-h': [usage, 0],
'--help': [usage, 0],
'-a': [about, 0],
'--about': [about, 0]
}
args = sys.argv[1:]
match = len(args)
for idx in range(0, len(args)):
if args[idx] in OPTS:
cmd, cmd_len = OPTS[args[idx]]
if cmd_len and idx + 1 < len(args):
print(cmd(args[idx + 1]))
else:
print(cmd())
else:
match -= 1
if not match:
print(usage())
# --- The end is near! ------------------------------------------------------ #