-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathdb.py
More file actions
33 lines (27 loc) · 1.08 KB
/
db.py
File metadata and controls
33 lines (27 loc) · 1.08 KB
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
from hashlib import blake2b
# the 'database' of users
users = []
class User:
def __init__(self, name: str, password: str, email: str):
self.name = name
self.password = blake2b(password.encode('UTF-8')).hexdigest()
self.email = email
self.plan = "basic"
self.reset_code = ""
def __repr__(self):
return f"NAME: {self.name}, EMAIL: {self.email}, PASSWD: {self.password}"
def reset_password(self, code: str, new_password: str):
if code != self.reset_code:
raise Exception("Invalid password reset code.")
self.password = blake2b(new_password.encode('UTF-8')).hexdigest()
# stub methods for actions related to creating a new user
def create_user(name: str, password: str, email: str):
print(f"DB: creating user database entry for {name} ({email}).")
new_user = User(name, password, email)
users.append(new_user)
return new_user
def find_user(email: str):
for user in users:
if user.email == email:
return user
raise Exception(f"User with email address {email} not found.")