Advertisement
Guest User

Untitled

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