Advertisement
Guest User

Untitled

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