-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_password.py
49 lines (38 loc) · 1.42 KB
/
random_password.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
"""
Create a 8 character long password that also has
the following characteristics:
1-2 special characters
1-2 digits
1/3 Upper digits
Remaining upper digits """
import random
from itertools import permutations
from numpy import array
# made changes to see in git #1
#added more comments using a branch
def selector(num, arr, chosen_ones):
for _ in range(num):
chosen_ones.append(random.choice(arr))
spec_char = ['!', '@', '#', '$', '&']
digits = [str(i) for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]]
lower_letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z']
upper_letters = [i.upper() for i in lower_letters]
def password_maker(t=True):
no_spec = random.choice(range(1, 3))
no_digits = random.choice(range(1, 3))
no_letters = 8 - no_spec - no_digits
no_upper = no_letters // 3
no_lower = no_letters - no_upper
chosen_ones = []
selector(no_spec, spec_char, chosen_ones)
selector(no_digits, digits, chosen_ones)
selector(no_upper, upper_letters, chosen_ones)
selector(no_lower, lower_letters, chosen_ones)
random.shuffle(chosen_ones)
chosen_ones = ''.join(chosen_ones)
if t:
print('Your newly generated password is: ', chosen_ones)
else:
return chosen_ones
password_maker()