lessssGo_V3
lessssGo_V3
def Create_Connection():
"""Create and return a connection to the database."""
con = sql.connect(host = "localhost", username = "root", passwd =
"9628", database = "riteshgamestoretest") #Replace ‘riteshgamestoretest’
with your datbase.
if not con.is_connected():
print("Connection to database failed.")
exit(0)
return con
def Fetch_Usernames():
try:
conn = Create_Connection()
cursor = conn.cursor(buffered = True)
query = "SELECT username,password FROM users" #Replace 'Users’ with
your actual table name
cursor.execute(query)
usernames = cursor.fetchall()
usrname = {}
for i,j in usernames:
usrname[i] = j
except Exception as e:
print("==============================")
print(f"An error occurred: {e}")
print("==============================")
finally:
# Close the cursor and connection
cursor.close()
conn.close()
return usrname
def Validate_Email(email):
if "@" in email and "." in email:
if len(email.split("@")[0]) < 4 or len(email.split("@")[1]) < 3:
return False
else:
True
else:
return False
def Validate_password(passwd):
'''For passsword validation'''
l = u = d = s = 0 # lowercase, uppercase, digit, specialchr.
if len(passwd) <= 8 and len(passwd) >= 20:
return False
else:
for i in passwd:
if i.isalpha():
if i.islower():
l += 1
else:
u += 1
elif i.isdigit():
d += 1
else:
s += 1
except Exception as e:
print("==============================")
print(f"An error occurred: {e}")
print("==============================")
finally:
# Close the cursor and connections
cursor.close()
conn.close()
def SignUp():
try:
while True:
print("==============================")
name = input("Enter your name: ")
except Exception as e:
print("==============================")
print(f"An error occurred: {e}")
print("==============================")
def LogIn():
try:
while True:
print("=======WELCOME BACK=======")
username = input("Enter your username: ")
usrnmaes = Fetch_Usernames()
while not (username in usrnmaes.keys()):
print("==============================")
print("Username does not exist!")
username = input("Enter your username(0-exit): ")
if username == "0":
break
else:
password = input("Enter your password: ")
if usrnmaes[username] == password:
print("LogIn succesful!")
break
else:
print("==============================")
print("Wrong password!")
except Exception as e:
print("==============================")
print(f"An error occurred: {e}")
print("==============================")
def Menu():
while True:
print("1. SignUp")
print("2. LogIn")
print("3. Exit")
try:
choice = int(input("Enter your choice: "))
if choice == 1:
SignUp()
elif choice == 2:
LogIn()
elif choice == 3:
exit(0)
else:
raise ValueError
except ValueError:
print("Invalid choice!")
Menu()