I have seen alot of threads to check if the field exists but i am a little confused i was wondering if someone could tell me hwot to check if it exists and to see if it is equal to an input which is a variable.
My code so far
import sqlite3
import datetime
import smtplib
now = datetime.datetime.now()
conn = sqlite3.connect("accounts.db")
c = conn.cursor()
def register():
username = input("Username: ")
password = input ("Password: ")
date = now.strftime("%d-%m-%Y %H-%M")
adminlevel = 0
c.execute("""INSERT INTO accounts
(username,password,date,adminlevel)
VALUES(?,?,?,?)""",(username,password,date,adminlevel))
conn.commit()
print("You have succesfully registered at " + date, "An email has been sent to you with your information!")
menu()
from getpass import getpass
def login():
def loggedin():
if adminlevel > 0:
print("Hello There Admin!")
print("Commands: ")
else:
print("Hello there {}".format(username))
print("Commands: Name, Date, Friend, Logout")
adminlevel = 0
username = input("Please enter your username: ")
password = getpass("Please enter your password: ")
admin = c.execute("select 1 from accounts where adminlevel > 0")
c.execute("select 1 from accounts where username = ? and password = ?", (username, password))
if c.fetchone():
print('Hello there! {}'.format(username))
loggedin()
else:
print("Username and Password Not Found!")
login()
def menu():
print("="*40)
print("Login & Registration System")
print("="*40)
choice = input("Login or Register? ")
if choice == "register":
register()
elif choice == "login":
login()
menu()
login()function? You should make more effort to make your question clear - it should not be necessary to read all of the code to figure out what the question might be.def info():does nothing (global variables should be declaredglobalin the function that uses them) andusername == username:will always be true - ifusernamewas defined, that is.