Advertisement
Guest User

Untitled

a guest
Mar 10th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. import sqlite3
  2.  
  3. def sign_up():
  4. username = input("Enter username: ")
  5. password = input("Enter password: ")
  6. first_name = input("Enter first name: ")
  7. last_name = input("Enter last name: ")
  8.  
  9. connection = sqlite3.connect('userinfo.db')
  10. c = connection.cursor()
  11.  
  12. c.execute("""INSERT INTO UserInfo VALUES ('%s', '%s', '%s', '%s')""" % (username, password, first_name, last_name))
  13.  
  14. connection.commit()
  15. connection.close()
  16.  
  17. def reset_password(username):
  18. user = username
  19. new_pass = input("Enter new password: ")
  20.  
  21. connection = sqlite3.connect('userinfo.db')
  22. c = connection.cursor()
  23. c.execute("""SELECT * FROM UserInfo""")
  24. table = c.fetchall()
  25.  
  26. for row in table:
  27. if user in row:
  28. c.execute("""UPDATE UserInfo SET Password='%s' WHERE Username='%s'""" % (new_pass, user))
  29. print("Success!")
  30.  
  31. connection.commit()
  32. connection.close()
  33.  
  34. def login_menu(name):
  35. while True:
  36. print("\nHello, %s" % (name))
  37. print("Select an option: ")
  38. print("1. Reset Password")
  39. print("2. Exit")
  40. choice = int(input("= "))
  41.  
  42. if choice == 1:
  43. username = input("Enter username: ")
  44. reset_password(username)
  45. elif choice == 2:
  46. print("Goodbye!")
  47. return False
  48. else:
  49. print("You did not select one!")
  50.  
  51. def login():
  52. flag = False
  53. name = ""
  54. while flag == False:
  55. username = input("\nEnter Username: ")
  56. password = input("Enter Password: ")
  57. connection = sqlite3.connect('userinfo.db')
  58. c = connection.cursor()
  59.  
  60. c.execute("""SELECT Username,Password,First_Name FROM UserInfo""")
  61. table = c.fetchall()
  62.  
  63. for row in table:
  64. if username in row:
  65. if row[1] == password:
  66. name = row[2]
  67. flag = True
  68. else:
  69. print("Incorrect password!")
  70. login_menu(name)
  71.  
  72. def menu():
  73. print("Welcome!")
  74. print("Select an option via the number!\n")
  75. print("1. Signup")
  76. print("2. Login")
  77.  
  78. choice = int(input("= "))
  79. if choice == 1:
  80. sign_up()
  81. elif choice == 2:
  82. login()
  83. else:
  84. print("You did not select one!")
  85. menu()
  86. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement