Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## List of logins that will work for said username and password given above
- usernames = ["admin", "Mason", "linux"]
- passwords = ["admin", "12345", "toor"]
- ## Ask for username and password from the user
- username = input("Username: ")
- password = input("Password: ")
- def login():
- ## allows for the var variable to be used outside of the function, to print the index
- ##from the list
- global var
- ## Checks for if the username and password is inside of the list
- try:
- var = usernames.index(username)
- var2 = passwords.index(password)
- ## Returns 0 if either one of the above values are not in the list
- except ValueError:
- return 0
- ## Checks to see if the index of both the username and password are in the same index
- if var == var2:
- return 1
- else:
- return 0
- ## Checks to see if login() function returns 1 after it is called, which would mean that
- ## the username and password are in the same index, allowing for the successful login
- if(login() == 1):
- print("Logged in as: " + usernames[var])
- else:
- print("Username or password is not correct")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement