Advertisement
Guest User

login_model

a guest
Feb 9th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Login_model extends CI_Model{
  4.     function __construct(){
  5.         parent::__construct();
  6.     }
  7.    
  8.     public function validate(){
  9.         // grab user input
  10.         $username = $this->input->post('username');
  11.         $password = md5($this->input->post('password'));
  12.        
  13.         // Prep the query
  14.         $this->db->where('nama_user', $username);
  15.         $this->db->where('password_user', $password);
  16.        
  17.         // Run the query
  18.         $query = $this->db->get('user');
  19.         // Let's check if there are any results
  20.         if($query->num_rows == 1)
  21.         {
  22.             // If there is a user, then create session data
  23.             $row = $query->row();
  24.             $data = array(
  25.                     'nama_user' => $row->nama_user,
  26.                     'password_user' => $row->password_user,
  27.                     );
  28.             $this->session->set_userdata($data);
  29.             return true;
  30.         }
  31.         // If the previous process did not validate
  32.         // then return false.
  33.         return false;
  34.     }
  35. }
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement