Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- import re
- def register():
- with conn:
- cur = conn.cursor()
- try:
- EmployeeID = int(input("Enter New Employee ID: "))
- FirstName = input("What's your first name:")
- while FirstName == "":
- FirstName = input("What's your first name:")
- FirstName = FirstName.title()
- LastName = input("What's your last name: ")
- while LastName == "":
- LastName = input("What's your first name:")
- LastName = LastName.title()
- Email = input("Email: ").lower()
- match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$', Email)
- if match is None:
- print('Bad Syntax')
- #raise ValueError('Bad Syntax')
- Password = input("Enter a password: ")
- Password = Password.lower()
- cur.execute(
- 'insert into employee values(?,?,?,?,?)',
- (EmployeeID, FirstName, LastName, Email, Password))
- cur.execute(
- 'select * from employee where EmployeeId=?',
- (EmployeeID,))
- results = cur.fetchall()
- print(results)
- except sqlite3.Error as e:
- print(e)
- print("User already exist")
- def login():
- with conn:
- cur = conn.cursor()
- try:
- loginTest = False # main condition to loop if email and password not met
- while not loginTest: # wrong email loopy
- userEmail = input("Email please: ")
- userEmail = userEmail.lower().replace(" ", "")
- userPassword = input("Password: ").strip()
- cur.execute(
- "SELECT COUNT (*) FROM Employee WHERE(Email= '" + userEmail.lower() + "' AND Password= '" + userPassword + "')")
- results = cur.fetchone() # return very first thing it finds that matches
- print(results[0]) # print first thing
- if results[0] == 1:
- print("Login successful")
- loginTest = True
- else:
- print("Login Unsuccessful")
- existingUser = input("Existing user?[yes/no]")
- if existingUser == "no":
- register()
- except:
- print("connection failed")
- conn = sqlite3.connect('OS_employee.db')
- with conn:
- cur = conn.cursor()
- print("successfully connected")
- existingUser = input("Existing user?[yes/no]")
- existingUser = existingUser.lower()
- while existingUser != "yes" or existingUser != "no":
- if existingUser == "no":
- register()
- break
- elif existingUser == "yes":
- login()
- break
- else:
- input("Invalid input. Please answer [yes/no]")
- existingUser = input("Existing user?[yes/no]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement