-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers_registration.py
133 lines (92 loc) · 3.19 KB
/
users_registration.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import mysql.connector
import bcrypt
mydb= mysql.connector.connect(
host="localhost",
user="root",
password="",
database= 'Registration'
)
mycursor= mydb.cursor()
# mycursor.execute('CREATE DATABASE Registration')
# mycursor.execute('CREATE TABLE Users (id INT, name VARCHAR(250), email VARCHAR(300), password VARCHAR(200))')
# sql='INSERT INTO Users(id,name,email,password) VALUES(%s,%s,%s,%s)'
# val= [
# (1, 'ama','[email protected]', '125dsdsdg'),
# (2, 'kofi', '[email protected]', '454f44df4'),
# (3, 'susu', '[email protected]', '5844wqqa45')
# ]
# mycursor.executemany(sql,val)
# mydb.commit()
# id_data=input("enter you id number :")
# name_data= input("enter your name :")
# email_data =input("enter your email :")
# password_data = input("enter your password :")
# salt = bcrypt.gensalt()
# hashed = bcrypt.hashpw(password_data.encode(), salt)
# def create_user():
# sql="INSERT INTO users(id, name, email, password) VALUES (%s,%s,%s,%s)"
# val = id_data,name_data,email_data,hashed
# mycursor.execute(sql,val)
# mydb.commit()
# create_user()
# def delete_user(num_id):
# sql = f"DELETE FROM users WHERE id= {num_id}"
# mycursor.execute(sql)
# mydb.commit()
# delete_user()
# set= input("Enter your new name: ")
# where= input(" Enter your current name: ")
# def update_user():
# sql= "UPDATE users SET name= %s WHERE name= %s "
# val= set, where
# mycursor.execute(sql,val)
# mydb.commit()
# update_user()
# id_data=input("enter you id number: ")
# name_data= input("enter your name: ")
# email_data =input("enter your email: ")
# password_data = input("enter your password: ")
salt = bcrypt.gensalt()
class user:
def __init__(self, id_data, name_data, email_data, password_data):
self.id= id_data
self.name= name_data
self.email= email_data
self.password= password_data
self.hashed = bcrypt.hashpw(password_data.encode(), salt)
def create_user(self):
sql="INSERT INTO users(id, name, email, password) VALUES (%s,%s,%s,%s)"
val = self.id, self.name,self.email,self.hashed
mycursor.execute(sql,val)
mydb.commit()
def delete_user(self):
sql = f"DELETE FROM users WHERE id= {self.id}"
mycursor.execute(sql)
mydb.commit()
def update_user(self,set,where):
sql= "UPDATE users SET name= %s WHERE name= %s "
val= set, where
mycursor.execute(sql,val)
mydb.commit()
# if and input_password== select:
# print('credential was correct, proceed')
# else:
# print("credential was wrong")
user1= user(1,'josh', '[email protected]','fd125467')
user1.create_user()
# user.delete_user(2)
# user()
def user_login(email,password):
sql= "SELECT* FROM Users WHERE email=%s password=%s"
val= (email,password)
mycursor.execute(sql,val)
myresult= mycursor.fetchall()
# x=[]
# for user in myresult:
# print(user[3])
# x.append(user[3])
if myresult == email and password :
print('credential was correct, proceed')
else:
print('credential was wrong')
user_login('[email protected]','5844wqqa45')