-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
99 lines (94 loc) · 4.13 KB
/
app.py
File metadata and controls
99 lines (94 loc) · 4.13 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
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
import mysql.connector
from pyfiglet import Figlet
database_connection = False
running = True
pass_weak = False
login_status = False
login_said = False
def database_connect(host_v,usr,password,datab):
global database_connection, db, mycursor
try:
db = mysql.connector.connect(
host=host_v,
user=usr,
passwd=password,
database=datab
)
mycursor = db.cursor()
if db:
database_connection = True
return "Connection to the database is working"
except:
return "Connection to the database wasn't successful"
def setup_database_connection():
global database_connection
host_v = input("Input the hostname (Type localhost if you're not sure): ")
usr = input("Input the database user: ")
password = input("Input the database password: ")
datab = input("Input the database name: ")
print(database_connect(host_v,usr,password,datab))
if database_connection == False:
exit()
f = Figlet(font='slant')
print(f.renderText('Login System'))
print("Welcome to Login System v1.3 by debugleader!")
print("")
while running:
if not database_connection:
setup_database_connection()
print("")
print("1) Create a table (Mandatory before registering or logging in): ")
print("2) Register")
print("3) Login")
print("4) Quit")
print("")
user_input = input("Input a number: ")
if user_input == str(4):
print("")
print("Thank you for using our program!")
exit()
elif user_input == str(1):
try:
mycursor.execute("CREATE TABLE system_data (name VARCHAR(20), password VARCHAR(20), personID int PRIMARY KEY AUTO_INCREMENT)")
print("Table created!")
except:
print("Table already created or something else went wrong!")
elif user_input == str(2):
register_name = input("Input your name: ")
while not pass_weak:
register_passwd = input("Input your password: ")
if (any(x.isupper() for x in register_passwd) and any(x.islower() for x in register_passwd) and any(x.isdigit() for x in register_passwd) and len(register_passwd) >= 8):
mycursor.execute(f"INSERT INTO system_data (name,password) VALUES ('{register_name}','{register_passwd}')")
db.commit()
pass_weak = True
print("")
print(f"Congratulations! Your name is {register_name} and your password is {register_passwd}!")
else:
print("Weak password, the password should contain at least an upper case letter, a lower case letter, a number and must be longer than 7 characters!")
pass_weak = False
elif user_input == str(3):
mycursor.execute("SELECT * FROM system_data")
credentials = []
for x in mycursor:
credentials.append(x)
while not login_status:
login_name = input("Input your name: ")
login_passwd = input("Input your password: ")
for counter in range(len(credentials)):
if login_name == credentials[counter][0]:
if login_passwd == credentials[counter][1]:
print("")
print("You successfully logged in, thank you really much for using our system :)")
print("")
print(f'The account name is called "{credentials[counter][0]}" and the password is "{credentials[counter][1]}"')
print(f"This account was the number {credentials[counter][2]} registered account!")
print("")
exit()
else:
if login_said == False:
print("Sorry, wrong username or password!")
login_said = True
elif login_said == False:
print("Sorry, wrong username or password!")
login_said = True
login_said = False