-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinmemorydb.py
More file actions
37 lines (28 loc) · 959 Bytes
/
inmemorydb.py
File metadata and controls
37 lines (28 loc) · 959 Bytes
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
from typing import Dict, Any, Optional
userCollection: Dict[Any, Any] = dict()
def initilize_db():
global userCollection
userCollection['admin'] = 'admin'
def get_user(user_name: str) -> Optional[str]:
global userCollection
if user_name in userCollection.keys():
return userCollection[user_name]
else:
return None
def is_user_exist(user_name: str) -> bool:
global userCollection
if user_name in userCollection.keys():
print(f"User name matched")
return True
else:
print(f"User does not exist")
return False
def set_user(user_name: str, password: str) -> bool:
global userCollection
if user_name in userCollection.keys():
print(f"User with name {user_name} already exist")
return False
else:
print(f"Adding new user with username: {user_name} and password: {password}")
userCollection[user_name] = password
return True