def username_check(username): # function for username vaildation # Checking the length of username is between 6 and 30 chracters if (len(username) >= 6) and (len(username) <= 30): # sql statement for checking existing users # Checks student database for username fetchstudents = ( "SELECT DISTINCT Students.Username from Students WHERE Username = ?" ) # Checkes teacher databaase for username fetchteachers = ( "SELECT DISTINCT Teachers.Username from Teachers WHERE Username = ?" ) cursor.execute( fetchstudents, [(username)]) # executes the above query on the student table cursor1.execute( fetchteachers, [(username)]) # execute the above query on the teacher table checking = cursor.fetchall( ) # stores the result of sql search done on the Student table checking1 = cursor1.fetchall( ) # stores the result of sql search done on the Teacher table if checking or checking1: # if checking or checking1 has values then return tkinter error messagebox.showerror( "Username", "That username has been taken please try another one") else: # if checking and checking 1 is none then return true return True else: #if username isn't in the range then return tkinter error message messagebox.showerror("Username", "Username has to be between 6 and 30 characters")
def username_check(username): # function for username vaildation # Checking the length of username is more than 6 charcters if len(username) >= 6: # sql statement for checking existing users # Checks student database for username fetchstudents = ( "SELECT DISTINCT Students.Username from Students WHERE Username = ?" ) # Checkes teacher databaase for username fetchteachers = ( "SELECT DISTINCT Teachers.Username from Teachers WHERE Username = ?" ) cursor.execute( fetchstudents, [(username)]) # executes the above query on the student table cursor1.execute( fetchteachers, [(username)]) # execute the above query on the teacher table checking = cursor.fetchall() # stores the result of sql search checking1 = cursor1.fetchall() if checking or checking1: messagebox.showerror( "Username", "That username has been taken please try another one") else: return True else: messagebox.showerror("Username", "Username has to be 6 or more characters")
def teacher_email( email ): # checks the email the user entered against the teacher database find_teacher = ("SELECT Teachers.email FROM Teachers WHERE email = ?") # sql statement checks based on email variable condition cursor1.execute(find_teacher, [(email)]) # execution of sql statement checking = cursor1.fetchone() # gets one value if checking is not None: # checks based on condition that there is values to check db_email = checking # sets the value db_email based on result if email == db_email: # checks user input against database value return True # if condition is met it returns true else: return False # if condition not met it returns false
def teacher_check(username, password): # Used for the login function this checks against the username and password the user enters in students table find_user1 = ("SELECT username,password FROM Teachers WHERE username = ?") # sql statement for getting the username and password cursor1.execute(find_user1, [(username)]) #executes the above sql code checking1 = cursor1.fetchone() # fetchs one of the values if checking1 is not None: # if there are values in check then it goes through this process db_user1, db_password1 = checking1 # gets username and password stored in the database if (username == db_user1) and (bcrypt.checkpw(password.encode("utf8"), db_password1) is True): #checks the database username and password against the username and password stored return True # if condition met return true else: return False # if condition not met return False
def get_question(type, level): # takes in params type and level query = "SELECT question,answer FROM maths_questions WHERE test_type = ? AND test_level = ?" # sql query resp = pd.read_sql_query(query, db, params=[ (type), (level) ]) # converts sql query into a pandas dataframe query1 = "SELECT COUNT(question_id) FROM maths_questions WHERE test_type=? AND test_level=?" # gets total amount of questions for the specific type and level (amount of records that met the requirements) cursor1.execute(query1, [(type), (level)]) # calculates the value of above query total = cursor1.fetchone()[0] # stores the value to a variable total rand_num = random_num( total) # runs the function to generate a non-duplicate random number if rand_num is not "stop": # continues until rand_num is stop return [resp["question"][rand_num], resp["Answer"][rand_num]] # returns the question and answer else: return ["No more Questions", "END"]