Advertisement
Guest User

Untitled

a guest
May 20th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2. class ModelAuth extends AuthAdapter
  3. {
  4.     /**
  5.      * Modelo a utilizar para el proceso de autenticacion
  6.      *
  7.      * @var String
  8.      */
  9.     protected $_model = 'usuarios';
  10.    
  11.     /**
  12.      * Asigna el modelo a utilizar
  13.      *  
  14.      * @param string $model nombre de modelo
  15.      */
  16.     public function setModel($model)
  17.     {
  18.         $this->_model = $model;
  19.     }
  20.    
  21.     /**
  22.      * check
  23.      *
  24.      * @param $username
  25.      * @param $password
  26.      * @return bool
  27.      */
  28.     protected function _check ($username, $password)
  29.     {
  30.         // TODO $_SERVER['HTTP_HOST'] puede ser una variable por si quieren ofrecer autenticacion desde cualquier host indicado
  31.         if(strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) === FALSE){
  32.             self::log('INTENTO HACK IP '.$_SERVER['HTTP_REFERER']);
  33.             $this->setError('Intento de Hack!');
  34.             return FALSE;
  35.         }
  36.         // TODO: revisar seguridad
  37.         $password = hash($this->_algos, $password);
  38.         //$username = addslashes($username);
  39.         $username = filter_var($username, FILTER_SANITIZE_MAGIC_QUOTES);
  40.         var_dump($username);die;
  41.         $model = Load::model($this->_model);
  42.         if ($model->find_first("$this->_login = '$username' AND $this->_pass = '$password'")) {
  43.             Session::set('id', $model->id);
  44.             Session::set($this->_key, TRUE);
  45.             return TRUE;
  46.         } else {
  47.             $this->setError('Error Login!');
  48.             Session::set($this->_key, FALSE);
  49.             return FALSE;
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement