-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
35 lines (26 loc) · 955 Bytes
/
generate.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
import string
import secrets
import logging
import subprocess
_alphanumeric = string.ascii_letters + string.digits
def ssid():
with open("cities.txt", "r") as file:
cities = file.readlines()
city = secrets.choice(cities).strip()
postfix = "".join(secrets.choice(_alphanumeric) for _ in range(2))
return f"{city}-{postfix.upper()}"
def password(length: int):
try:
return subprocess.check_output(["pwgen", str(length), "1"]).decode().strip()
except FileNotFoundError:
logging.warning(
"pwgen not found, using fallback implementation which produces less memorable passwords."
)
while True:
password = "".join(secrets.choice(_alphanumeric) for _ in range(length))
if (
any(c.islower() for c in password)
and any(c.isupper() for c in password)
and sum(c.isdigit() for c in password) >= 3
):
return password