Advertisement
Guest User

Untitled

a guest
Dec 19th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import sqlite3
  2. import sys
  3. import getpass
  4.  
  5. sqlite_file = 'C:/Assignment/PADS/UROTS/urots_db.sqlite'
  6. users_tbl = 'USERS_TBL'
  7. toys_tbl = 'TOYS_TBL'
  8.  
  9. conn = sqlite3.connect(sqlite_file)
  10. c = conn.cursor()
  11.  
  12. def main():
  13. print('This module does not run by itself. Use urots_main.py')
  14.  
  15. def login_check():
  16. try:
  17. username = input('Enter username: ')
  18. c.execute('SELECT * from {} WHERE username="{}"'.format(users_tbl, username))
  19. row = c.fetchone()
  20. if row is None:
  21. print('User "{}" does not exists!!!'.format(username))
  22. sys.exit()
  23.  
  24. pass_try = 0
  25. while pass_try < 3:
  26. password = getpass.getpass()
  27. if password == row[2]:
  28. break
  29. elif password != row[2] and pass_try < 2:
  30. print('Incorrect password, try again...')
  31. elif pass_try == 2 and password != row[2]:
  32. print('Too manu retries. Exiting program...')
  33. sys.exit()
  34.  
  35. pass_try += 1
  36.  
  37. role = row[3]
  38. global user_id
  39. user_id = row[0]
  40. return role
  41.  
  42. except sqlite3.Error as e:
  43. print('An error has occurred:', e.args[0])
  44.  
  45.  
  46. if __name__ == "__main__":
  47. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement