-
Notifications
You must be signed in to change notification settings - Fork 1
/
Authenticate.py
108 lines (92 loc) · 3.81 KB
/
Authenticate.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
from tkinter import *
import sqlite3
flag = False
login_root = Tk()
def check_credentials(username_entry, password_entry):
global flag
flag = False
con = sqlite3.connect('automate.db')
cursor = con.cursor()
rows = cursor.execute('SELECT username,password FROM users WHERE username="' + username_entry + '"').fetchall()
if len(rows) == 0:
print('No such account')
elif len(rows) == 1:
if rows[0][1] == password_entry:
flag = True
login_root.destroy()
cursor.execute('DELETE FROM current_user')
cursor.execute('INSERT INTO current_user SELECT * FROM users WHERE username = "' + username_entry + '"')
con.commit()
else:
print('Incorrect password')
else:
print('Database error: More than one users with same username found!')
con.close()
def new_entry(username_entry, password_entry):
con = sqlite3.connect('automate.db')
cursor = con.cursor()
rows = cursor.execute('SELECT username,password FROM users WHERE username="' + username_entry + '"').fetchall()
if len(rows) == 0:
cursor.execute(
'INSERT INTO users (username,password) VALUES ("' + username_entry + '", "' + password_entry + '")'
)
con.commit()
print('Account created')
elif len(rows) == 1:
print('User already exists')
else:
print('Database error: More than one users with same username found!')
con.close()
def del_entry(username_entry, password_entry):
con = sqlite3.connect('automate.db')
cursor = con.cursor()
rows = cursor.execute('SELECT username,password FROM users WHERE username="' + username_entry + '"').fetchall()
if len(rows) == 0:
print('No such account')
elif len(rows) == 1:
if rows[0][1] == password_entry:
cursor.execute('DELETE FROM users WHERE username="' + username_entry + '"')
con.commit()
print('Account deleted')
else:
print('Incorrect password')
else:
print('Database error: More than one users with same username found!')
con.close()
def login_initialize():
login_root.title('Login')
login_frame = Frame(login_root, padx=10, pady=10)
login_frame.grid(row=0, column=0, sticky=N + E + W + S)
Label(login_frame, text='LOGIN', font=('', 35), pady=10).grid(row=0, column=0, sticky=N + S + E + W)
Label(login_frame, text='Username : ', font=('', 20), pady=5, padx=5).grid(row=1, column=0, sticky=N + S + E + W)
Label(login_frame, text='Password : ', font=('', 20), pady=5, padx=5).grid(row=2, column=0, sticky=N + S + E + W)
username_entry = Entry(login_frame, bd=5, font=('', 15))
username_entry.grid(row=1, column=1, sticky=N + S + E + W)
password_entry = Entry(login_frame, show='*', bd=5, font=('', 15))
password_entry.grid(row=2, column=1, sticky=N + S + E + W)
Button(
login_frame,
text='Del User',
bd=3, font=('', 15), padx=5, pady=5,
command=lambda: del_entry(username_entry.get(), password_entry.get())
).grid(row=3, column=0, sticky=N + S + E + W)
Button(
login_frame,
text='Sign Up',
bd=3, font=('', 15), padx=5, pady=5,
command=lambda: new_entry(username_entry.get(), password_entry.get())
).grid(row=3, column=1, sticky=N + S + E + W)
Button(
login_frame,
text='Login',
bd=3, font=('', 15), padx=5, pady=5,
command=lambda: check_credentials(username_entry.get(), password_entry.get())
).grid(row=4, column=0, columnspan=2, sticky=N + S + E + W)
login_root.mainloop()
def authenticate():
global flag
login_initialize()
if flag:
return True
else:
return False