-
Notifications
You must be signed in to change notification settings - Fork 4
/
mongo.py
61 lines (46 loc) · 1.4 KB
/
mongo.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from passlib.hash import pbkdf2_sha256
import pymongo
# Establishing the connection
username = "daciit"
password = "supplychain"
srv = "mongodb+srv://{}:{}@supplychain-u6nhl.mongodb.net/test?retryWrites=true&w=majority".format(
username, password)
client = pymongo.MongoClient(srv)
print("Connection Established")
db = client['Authenication']
logincol = db['Login']
FeedBack = client['FeedBack']
Message = FeedBack['Message']
def Register(email, name, password, category, hashc):
q1 = {"email": email}
p = logincol.find(q1)
check = False
for i in p:
if email == i['email']:
check = True
if check:
print("email adress already in database")
return False
else:
password = pbkdf2_sha256.hash(password)
q2 = {"name": name, "email": email,
"password": password, 'hash': hashc}
q2['category'] = category
if category == "SME":
q2['approval'] = False
# print(q2)
r = logincol.insert_one(q2)
return True
def Login(email, password):
l1 = {"email": email}
res = logincol.find(l1)
data = {}
data['check'] = False
for i in res:
if pbkdf2_sha256.verify(password, i['password']):
data['name'] = i['name']
data['category'] = i['category']
data['check'] = True
data['hash'] = i['hash']
print(data)
return data