-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_generator.py
51 lines (35 loc) · 1.52 KB
/
password_generator.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import random
import pyperclip
from constants import CHAR_TYPES_MAP
def get_available_characters(selected_char_types: list[str]) -> str:
"""
Get a string of available characters based on the selected character types.
Args:
selected_char_types (list[str]): List of selected character type keys.
Returns:
str: A string containing all available characters for the selected types.
"""
return ''.join(''.join(CHAR_TYPES_MAP[char_type]) for char_type in selected_char_types)
def generate_password(available_chars: str, selected_char_types: list[str], password_length: int) -> str:
"""
Generate a password based on the available characters, ensuring at least one character of each selected type.
Args:
available_chars (str): A string of available characters.
selected_char_types (list[str]): List of selected character type keys.
password_length (int): The desired password length.
Returns:
str: A generated password.
"""
password = [random.choice(CHAR_TYPES_MAP[char_type]) for char_type in selected_char_types]
remaining_length = password_length - len(password)
password += random.sample(available_chars, remaining_length)
random.shuffle(password)
return ''.join(password)
def copy_password_to_clipboard(password: str) -> None:
"""
Copy the generated password to the clipboard.
Args:
password (str): The generated password.
"""
pyperclip.copy(password)
return None