Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User
- {
- private $_db;
- function __construct() {
- try {
- $this->_db = DBHandler::instance(); // Singleton pattern if exists return else creat new connection
- } catch (PDOException $e) {
- echo '<p class="bg-danger">'.$e->getMessage().'</p>';;
- }
- }
- public function authorize($login, $password) {
- $login = addslashes($login);
- $password = addslashes($password);
- try {
- $stmt = $this->_db->prepare('SELECT * FROM users WHERE login = :login AND password = :password');
- $stmt->bindParam(':login', $login);
- $stmt->bindParam(':password', $password);
- $stmt->execute();
- $user = $stmt->fetch();
- } catch(PDOException $e) {
- echo '<p class="bg-danger">'.$e->getMessage().'</p>';
- }
- $this->authorized = !!$user;
- }
- }
Add Comment
Please, Sign In to add comment