Advertisement
Guest User

Untitled

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