-
-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathRandom-password.py
More file actions
54 lines (29 loc) · 1.18 KB
/
Copy pathRandom-password.py
File metadata and controls
54 lines (29 loc) · 1.18 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
44
45
46
47
48
49
50
51
52
53
54
import string
import random
alphabets = list(string.ascii_letters)
digits = list(string.digits)
special_characters = list("!@#$%^&*()")
characters = list(string.ascii_letters + string.digits + "!@#$%^&*()")
def generate_random_password():
length = int(input("Enter The Length Of Password: "))
alphabets_count = int(input("How Many Alphabets You Want : "))
digits_count = int(input("How Many Digits You Want : "))
special_characters_count = int(input("How Many Special Character You Want: "))
characters_count = alphabets_count + digits_count + special_characters_count
if characters_count > length:
print("Characters total count is greater than the password length")
return
password = []
for i in range(alphabets_count):
password.append(random.choice(alphabets))
for i in range(digits_count):
password.append(random.choice(digits))
for i in range(special_characters_count):
password.append(random.choice(special_characters))
if characters_count < length:
random.shuffle(characters)
for i in range(length - characters_count):
password.append(random.choice(characters))
random.shuffle(password)
print("".join(password))
generate_random_password()