-
Notifications
You must be signed in to change notification settings - Fork 1
/
23-password-generator.py
21 lines (19 loc) · 1.15 KB
/
23-password-generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import string
import random
def pwgen(length, with_digits=True, with_uppercase=True):
if with_digits and with_uppercase:
while True:
psw = ''.join(random.choices(string.ascii_lowercase + string.digits + string.ascii_uppercase, k=length))
if any(character in string.ascii_lowercase for character in psw) and any(character in string.digits for character in psw) and any(character in string.ascii_uppercase for character in psw):
return psw
elif with_digits:
while True:
psw = ''.join(random.choices(string.ascii_lowercase + string.digits, k=length))
if any(character in string.ascii_lowercase for character in psw) and any(character in string.digits for character in psw):
return psw
elif with_uppercase:
while True:
psw = ''.join(random.choices(string.ascii_lowercase + string.ascii_uppercase, k=length))
if any(character in string.ascii_lowercase for character in psw) and any(character in string.ascii_uppercase for character in psw):
return psw
return ''.join(random.choices(string.ascii_lowercase, k=length))