-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.py
22 lines (19 loc) · 1.06 KB
/
password.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Password class
import random
class Password:
def __init__(self):
self.letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
self.numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
self.symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
self.nr_letters = random.randint(8, 10)
self.nr_symbols = random.randint(2, 4)
self.nr_numbers = random.randint(2, 4)
def create_password(self):
password_list = [random.choice(self.letters) for _ in range(self.nr_letters)]
password_list += [random.choice(self.numbers) for _ in range(self.nr_numbers)]
password_list += [random.choice(self.symbols) for _ in range(self.nr_symbols)]
random.shuffle(password_list)
password = "".join(password_list)
return password