Advertisement
Guest User

Untitled

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