Skip to content

Examples

ConnorC18 edited this page Mar 24, 2019 · 5 revisions

Python Authentication Library Examples

Contents

Functions

Load Library
from loginSystem import * # Loads the login library
Sign Up
signup() # Will return True or the error message thrown by the function
Login
login() # Will return True or "incorrectinfo" or "noaccount" depending on the error.
Check If User Is Logged In
checkLoggedIn() # Will return True of False
Reset Password
passwordReset() # Will return True or "noemail" or "wrongsecurityquestionanswer"
Session Info
print(sessionInfo["username"]) # Will return the current logged in users, username
Logout
logout()  # Will return True or "notloggedin"

Usage

Check if signup worked
out = signUp() 
if (out != True):
    print("Sign Up Error! Please try again.")
    error = out 
Check if login worked
out = login()
switcher = {
    "incorrectinfo": "Error: Incorrect Login Details.",
    "noaccount": "Error: No Account in that name."    
}
print(switcher.get(out, "Unknown Error!"))
Check if user is logged in
if (checkLoggedIn()):
    print("Loading Account Page")
else:
    print("Error user is not logged in")
Check if password reset worked
out = passwordReset()
switcher = {
    "wrongsecurityquestionanswer": "Error: Incorrect Security Question Answer.",
    "noemail": "Error: No Account in that email."    
}
print(switcher.get(out, "Unknown Error!"))
Get session information
print("Username = ",sessionInfo["username"])
Check if logout worked
out = logout()
if (out != True):
    print("User has logged out")
else:
    print("Error: No logged in user")