-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnection.py
More file actions
46 lines (38 loc) · 1.34 KB
/
Copy pathConnection.py
File metadata and controls
46 lines (38 loc) · 1.34 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
34
35
36
37
38
39
40
41
42
43
44
45
46
from pymongo import MongoClient
import bcrypt
cluster = MongoClient(
"mongodb+srv://Logan:lolo123@cluster0.igyjs.mongodb.net/ecole?retryWrites=true&w=majority")
db = cluster.testdb
collection = db.testcollection
role = db.roles
class Connection:
def __init__(self, username, password):
self.username = username
self.__password = password
@property
def check_user_exist(self):
"""
:return: 1 if the user exist, 0 if the user dont exist
:PRE:
:POST:
:RAISE:
"""
if collection.find_one({"username": self.username}):
return True
return False
@property
def get_user_data_from_db(self):
if self.check_user_exist:
return collection.find_one({"username": self.username})
else:
return False
@property
def check_password(self):
if self.get_user_data_from_db:
dic_data = self.get_user_data_from_db
password_register_in_database = dic_data["password"]
password_crypted = bytes(self.__password, encoding="utf-8")
if bcrypt.checkpw(password_crypted, password_register_in_database):
return "Welcome"
return "Username or password incorrect"
return "Username or password incorrect"