Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. import sqlite3
  2.  
  3. def register():
  4. with conn:
  5. cur = conn.cursor()
  6. try:
  7. EmployeeID = int(input("Enter New Employee ID: "))
  8. #checkExisting = cur.execute(
  9. # 'select EmployeeID from Employee table where EmployeeID = '
  10. #)
  11. #if EmployeeID ==
  12.  
  13. FirstName = input("What's your first name:")
  14. FirstName = FirstName.title()
  15.  
  16.  
  17. LastName = input("What's your last name: ")
  18. LastName = LastName.title()
  19.  
  20. Email = input("Email: ")
  21. Email = Email.lower()
  22.  
  23. Password = input("Enter a password: ")
  24. Password = Password.lower()
  25.  
  26. cur.execute(
  27. 'insert into employee values(?,?,?,?,?)',
  28. (EmployeeID, FirstName, LastName, Email, Password))
  29. cur.execute(
  30. 'select * from employee where EmployeeId=?',
  31. (EmployeeID,))
  32.  
  33. results = cur.fetchall()
  34. print(results)
  35. except sqlite3.IntegrityError:
  36. print("Connection Failed")
  37.  
  38.  
  39. def login():
  40. with conn:
  41. cur = conn.cursor()
  42. try:
  43. loginTest = False # main condition to loop if email and password not met
  44. while not loginTest: # wrong email loopy
  45. userEmail = input("Email please: ")
  46. userEmail = userEmail.lower()
  47. userEmail = userEmail.replace(" ", "")
  48. userPassword = input("Password: ")
  49. userPassword = userPassword.strip()
  50. cur.execute(
  51. "SELECT COUNT (*) FROM Employee WHERE(Email= '" + userEmail.lower() + "' AND Password= '" + userPassword + "')")
  52. results = cur.fetchone() # return very first thing it finds that matches
  53. print(results[0]) # print first thing
  54. if results[0] == 1:
  55. print("Login successful")
  56. loginTest = True
  57. else:
  58. print("Login Unsucessful")
  59. existingUser = input("Existing user?[yes/no]")
  60. if existingUser == "no":
  61. register()
  62. except:
  63. print("connection failed")
  64.  
  65.  
  66. conn = sqlite3.connect('OS_employee.db')
  67. with conn:
  68. cur = conn.cursor()
  69. print("successfully connected")
  70.  
  71. existingUser = input("Existing user?[yes/no]")
  72. existingUser = existingUser.lower()
  73. while existingUser != "yes" or existingUser != "no":
  74. if existingUser == "no":
  75. register()
  76. break
  77. elif existingUser == "yes":
  78. login()
  79. break
  80. else:
  81. input("Invalid input. Please answer [yes/no]")
  82. existingUser = input("Existing user?[yes/no]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement