Guest User

login/registration

a guest
Nov 27th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import sqlite3
  2. def register():
  3. with conn:
  4. cur = conn.cursor()
  5. try:
  6. EmployeeID = int(input("Enter New Employee ID: "))
  7.  
  8. FirstName = input("What's your first name:")
  9. FirstName = FirstName.title()
  10.  
  11. LastName = input("what's your last name: ")
  12. LastName = LastName.title()
  13.  
  14. Email = input("Email: ")
  15. Email = Email.lower()
  16.  
  17. Password = input("Enter a password: ")
  18. Password = Password.lower()
  19.  
  20. cur.execute(
  21. 'insert into employee values(?,?,?,?,?)',
  22. (EmployeeID, FirstName, LastName, Email, Password))
  23. cur.execute(
  24. 'select * from employee where EmployeeId=?',
  25. (EmployeeID,))
  26.  
  27. results = cur.fetchall()
  28. print(results)
  29. except sqlite3.IntegrityError:
  30. print("Connection Failed")
  31. def login():
  32. with conn:
  33. cur = conn.cursor()
  34. try:
  35. loginTest = False # main condition to loop if email and password not met
  36. while not loginTest: # wrong email loopy
  37. userEmail = input("Email please: ")
  38. userEmail = userEmail.replace(" ", "")
  39. userPassword = input("Password: ")
  40. userPassword = userPassword.strip()
  41. cur.execute(
  42. "SELECT COUNT (*) FROM Employee WHERE(Email= '" + userEmail.lower() + "' AND Password= '" + userPassword + "')")
  43. results = cur.fetchone() # return very first thing it finds that matches
  44. print(results[0]) # print first thing
  45. if results[0] == 1:
  46. print("login successful")
  47. loginTest = True
  48. else:
  49. print("no login bithc")
  50. existingUser = input("Existing user?[yes/no]")
  51. if existingUser == "no":
  52. register()
  53. except:
  54. print("connection failed")
  55.  
  56.  
  57. conn = sqlite3.connect('OS_employee.db')
  58. with conn:
  59. cur = conn.cursor()
  60. print("successfully connected")
  61. existingUser = input("Existing user?[yes/no]")
  62. if existingUser == "no":
  63. register()
  64. else:
  65. login()
Add Comment
Please, Sign In to add comment