Advertisement
Raulwynn

Untitled

Oct 30th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. '''
  2.  
  3. Create a program that asks the user for a series of first and last names. Create a username combining the first letter of the first name with the entire last name (for example, Colby Peterson would be cpeterson) and save the list of usernames to a file. The program should continue asking for names until the user indicates quit.
  4. This file does NOT have to be sorted; but you might consider doing so.
  5. Do the same for passcodes (use the first letter of the first name and the last letter of the last name to generate the passcode). Save this to a different file.
  6. Next, the program should ask the user to log in; if the username matches an entry in the username file, AND the passcode matches an entry in the passcode file, the program should display "Access Allowed." Otherwise, the program should display "Invalid Username or Passcode; please try again" and allow the user to attempt to re-try.
  7. (note: Please do NOT disable CTRL-C to break out of the program!)
  8.  
  9. '''
  10.  
  11. #introduction
  12. with open("file.txt", "a") as a:
  13. pass
  14.  
  15. #intro
  16. print("Please enter a first and last name. Type 'stop' to stop adding users.")
  17. print("")
  18.  
  19. #input
  20. while True:
  21. with open("file.txt", "w") as w:
  22. i = input(str("\t Name > "))
  23. if i == "stop":
  24. break
  25. else:
  26. #try:
  27. user = i.split(' ')
  28. user = user[0][0].lower() + user[1].lower()
  29. print(" Username :",user,"\n\t\t\t...added! -Please create a password.")
  30. passw = input(" Password > ")
  31. #try:
  32. userpass = str(user) + "." + str(passw) + "\n"
  33. print(userpass)
  34. w.write(userpass)
  35. #except:
  36. print("ERROR 2: Unable to write USERPASS.")
  37. #except:
  38. print("ERROR 1: Please input 'Firstname Lastname'.")
  39. print("")
  40.  
  41.  
  42. print("")
  43. print("Please Login")
  44. u = input("User > ")
  45. p = input("Pass > ")
  46. up = str(u) + "." + str(p)
  47.  
  48. with open("file.txt", "r") as r:
  49. if up != 1:
  50. for l in r:
  51. print(up)
  52. print(l.strip())
  53. if up == l.strip():
  54. print("Access Allowed!")
  55. else:
  56. print("ERROR 3:Username or password incorrect. Please try again.")
  57.  
  58. [OUTPUT:]
  59. ...(User inputs to create login information above)...
  60.  
  61. Please Login
  62. User > uname
  63. Pass > password
  64.  
  65. Process finished with exit code 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement