Advertisement
Guest User

Simple Password and username login

a guest
May 28th, 2018
8,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. ## List of logins that will work for said username and password given above
  2. usernames = ["admin", "Mason", "linux"]
  3. passwords = ["admin", "12345", "toor"]
  4.  
  5.  
  6. ## Ask for username and password from the user
  7. username = input("Username: ")
  8. password = input("Password: ")
  9.  
  10. def login():
  11.     ## allows for the var variable to be used outside of the function, to print the index
  12.     ##from the list
  13.     global var
  14.  
  15.     ## Checks for if the username and password is inside of the list
  16.     try:
  17.         var = usernames.index(username)
  18.         var2 = passwords.index(password)
  19.     ## Returns 0 if either one of the above values are not in the list
  20.     except ValueError:
  21.         return 0
  22.  
  23.     ## Checks to see if the index of both the username and password are in the same index
  24.     if var == var2:
  25.         return 1
  26.     else:
  27.         return 0
  28.  
  29. ## Checks to see if login() function returns 1 after it is called, which would mean that
  30. ## the username and password are in the same index, allowing for the successful login
  31. if(login() == 1):
  32.     print("Logged in as: " + usernames[var])
  33. else:
  34.     print("Username or password is not correct")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement