Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from xpcom import components, verbose
- from sqlite3 import dbapi2 as sqlite
- import hashlib, os, sys, tarfile, urllib
- class splash_2_py:
- _com_interfaces_ = components.interfaces.nsISplash
- _reg_clsid_ = "{C93B60BC-CD5A-4C8E-8876-61B16CAD86C6}"
- _reg_contractid_ = "@emporos.net/nsISplash;1"
- """
- This file holds all the required python functions and settings for the opening splash screen for
- the Emporos POS system.
- """
- def __init__(self):
- """
- Build run time properties.
- """
- self.db_file = ""
- self.conn = False
- self.cur = False
- # AUTH FAIL RESPONSES
- self.AUTH_ERROR_NO_DATABASE = -10 # Username not found
- self.AUTH_ERROR_INVALID_USERNAME = -11 # Username not found
- self.AUTH_ERROR_USER_IS_LOCKED = -12 # User alread locked
- self.AUTH_ERROR_USER_JUST_LOCKED = -13 # User locked after this attempt to login
- self.AUTH_ERROR_AUTH_FAILED = -14 # User locked after this attempt to login
- def auth_user(self, username, password):
- """
- Description:
- Authenticate a user's credentials. On success update the Whoami table's user_id with
- returned user_id and return the user_id. If the Otherwise update the Whoami table's user_id to 0 and
- return False.
- Params:
- String username
- String password
- Return:
- Boolean Return user id or error number.
- """
- # Make sure we have a DB connection
- if self.cur:
- user_id = False
- user_lock_sql = "SELECT fail_count, is_locked FROM Users WHERE username =?"
- self.cur.execute(user_lock_sql, (username,))
- user_lock = self.cur.fetchone()
- if user_lock:
- if user_lock[1] == 1:
- return self.AUTH_ERROR_USER_IS_LOCKED
- if user_lock[0] >= 5:
- lock_user_sql = "UPDATE Users SET is_locked = '1' WHERE username =?"
- self.cur.execute(lock_user_sql,(username,))
- self.conn.commit()
- return self.AUTH_ERROR_USER_JUST_LOCKED
- else:
- return self.AUTH_ERROR_INVALID_USERNAME
- # Validate user against DB
- auth_user_sql = "SELECT id FROM Users WHERE username =? AND password =?"
- self.cur.execute(auth_user_sql, (username, hashlib.md5(password).hexdigest()))
- user = self.cur.fetchone()
- if user:
- user_id = int(user[0])
- update_whoami_sql = "UPDATE Whoami SET user_id =?"
- self.cur.execute(update_whoami_sql,(user_id,))
- self.conn.commit()
- if user_id:
- return user_id
- add_fail_count_sql = "UPDATE Users SET fail_count = fail_count + 1 WHERE username =?"
- self.cur.execute(add_fail_count_sql,(username,))
- self.conn.commit()
- return self.AUTH_ERROR_AUTH_FAILED
- print "Auth User Error: No database"
- return self.AUTH_ERROR_NO_DATABASE
Add Comment
Please, Sign In to add comment