Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import pymysql
  2.  
  3. # Connect to the database
  4. connection = pymysql.connect(host='localhost',
  5. user='root',
  6. password='',
  7. db='python_code',
  8. charset='utf8mb4',
  9. cursorclass=pymysql.cursors.DictCursor)
  10. class LoginModel:
  11. def check_user(self, data):
  12.  
  13. try:
  14. with connection.cursor() as cursor:
  15. # Read a single record
  16. sql = "SELECT `username` FROM `users` WHERE `username`=%s"
  17. cursor.execute(sql, (data.username))
  18. user = cursor.fetchone()
  19. print(user)
  20.  
  21. if user:
  22. if (user, data.password):
  23. return user
  24. else:
  25. return False
  26. else:
  27. return False
  28.  
  29. finally:
  30. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement