Advertisement
kukuhit_

Auth_model.php Models

Mar 4th, 2017
23,794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Auth_model extends CI_Model {
  4.  
  5.     private $table = "user";
  6.     private $_data = array();
  7.  
  8.     public function validate()
  9.     {
  10.         $username = $this->input->post('username');
  11.         $password = $this->input->post('password');
  12.  
  13.         $this->db->where("username", $username);
  14.         $query = $this->db->get($this->table);
  15.  
  16.         if ($query->num_rows())
  17.         {
  18.             // found row by username   
  19.             $row = $query->row_array();
  20.  
  21.             // now check for the password
  22.             if ($row['password'] == sha1($password))
  23.             {
  24.                 // we not need password to store in session
  25.                 unset($row['password']);
  26.                 $this->_data = $row;
  27.                 return ERR_NONE;
  28.             }
  29.  
  30.             // password not match
  31.             return ERR_INVALID_PASSWORD;
  32.         }
  33.         else {
  34.             // not found
  35.             return ERR_INVALID_USERNAME;
  36.         }
  37.     }
  38.  
  39.     public function get_data()
  40.     {
  41.         return $this->_data;
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement