Added function for password generation is utils.py
This commit is contained in:
parent
b8113dc47b
commit
2c07b3bed2
@ -1,5 +1,7 @@
|
||||
import io
|
||||
import string
|
||||
import time
|
||||
from random import SystemRandom
|
||||
from typing import Self, Type
|
||||
|
||||
import pydantic
|
||||
@ -99,3 +101,22 @@ def check_passwd(passwd: str) -> bool:
|
||||
def check_account(name: str, login: str, passwd: str) -> bool:
|
||||
"""Runs checks for account name, login and password"""
|
||||
return check_account_name(name) and check_login(login) and check_passwd(passwd)
|
||||
|
||||
|
||||
def gen_passwd() -> str:
|
||||
"""Generates password of length 32"""
|
||||
choices = SystemRandom().choices
|
||||
chars = frozenset(string.ascii_letters + string.digits + string.punctuation)
|
||||
# Remove backtick and pipe characters and convert into tuple
|
||||
chars = tuple(chars.difference("`|"))
|
||||
while True:
|
||||
passwd = "".join(choices(chars, k=32))
|
||||
passwd_chars = frozenset(passwd)
|
||||
# If there is at least one lowercase character, uppercase character
|
||||
# and one punctuation character
|
||||
if (
|
||||
passwd_chars.intersection(string.ascii_lowercase)
|
||||
and passwd_chars.intersection(string.ascii_uppercase)
|
||||
and passwd_chars.intersection(string.punctuation)
|
||||
):
|
||||
return passwd
|
||||
|
Reference in New Issue
Block a user