Advertisement
Guest User

Python simple Username and password check

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