13 lines
303 B
Python
13 lines
303 B
Python
import random
|
|
import secrets
|
|
import string
|
|
|
|
|
|
def generate_password(
|
|
length: int = 20,
|
|
*,
|
|
secure: bool = True,
|
|
) -> str:
|
|
alphabet = string.ascii_letters + string.digits
|
|
chooser = secrets.choice if secure else random.choice
|
|
return "".join(chooser(alphabet) for _ in range(length))
|