Advertisement
Guest User

Untitled

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