-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_password_gen.py
More file actions
43 lines (34 loc) · 1.03 KB
/
random_password_gen.py
File metadata and controls
43 lines (34 loc) · 1.03 KB
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
import random
import math
alpha = "abcdefghijklmnopqrstuvwxyz"
num = "0123456789"
special = "@#$%&*"
# pass_len=random.randint(8,13) #without User INput
pass_len = int(input("Enter Password Length"))
# length of password by 50-30-20 formula
alpha_len = pass_len//2
num_len = math.ceil(pass_len*30/100)
special_len = pass_len-(alpha_len+num_len)
password = []
def generate_pass(length, array, is_alpha=False):
for i in range(length):
index = random.randint(0, len(array) - 1)
character = array[index]
if is_alpha:
case = random.randint(0, 1)
if case == 1:
character = character.upper()
password.append(character)
# alpha password
generate_pass(alpha_len, alpha, True)
# numeric password
generate_pass(num_len, num)
# special Character password
generate_pass(special_len, special)
# suffle the generated password list
random.shuffle(password)
# convert List To string
gen_password = ""
for i in password:
gen_password = gen_password + str(i)
print(gen_password)