-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpassword_generator.py
33 lines (26 loc) · 994 Bytes
/
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
import random
import string
class PasswordGenerator:
def __init__(
self,
letters_amount: int,
symbols_amount: int,
numbers_amount: int,
):
self.letters_amount = letters_amount
self.symbols_amount = symbols_amount
self.numbers_amount = numbers_amount
self.letters = list(string.ascii_letters)
self.symbols = list(string.punctuation)
self.numbers = [i for i in range(10)]
self.password = []
def generate_password(self):
self._append_to_password_from(self.letters, self.letters_amount)
self._append_to_password_from(self.symbols, self.symbols_amount)
self._append_to_password_from(self.numbers, self.numbers_amount)
random.shuffle(self.password)
return ''.join(self.password)
def _append_to_password_from(self, lst: list, amount: int):
for _ in range(amount):
ch = random.choice(lst)
self.password.append(str(ch))