Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Ask for username and password from the user
- username = input("Username: ")
- password = input("Password: ")
- ## List of logins that will work for said username and password given above
- usernames = ["admin", "Mason", "Tux"]
- passwords = ["admin", "7890", "GoodPassword"]
- ## Start the login Function
- 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 equals 1 after it is called, which would mean that the username and password are in the
- ## same index, allowing for the login
- if(login() == 1):
- print("Logged In: " + usernames[var])
- else:
- print("Username or password is not correct")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement