Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Auth_lib
- {
- function Auth_lib()
- {
- $this->ci =& get_instance();
- }
- function login($username, $password)
- {
- $password = md5($password);
- $this->ci->db->select('user_id');
- $this->ci->db->where('user_username', $username);
- $this->ci->db->where('user_password', $password);
- $this->ci->db->limit(1);
- //Execute Active Record Query that was just built
- $query = $this->ci->db->get('users');
- // If there is a user found with those credentials then store some vital data into the Session
- if ($query->num_rows() > 0) {
- $row = $query->row();
- $data = array(
- 'username' => $username,
- 'user_id' => $row->user_id,
- 'logged_in' => TRUE//,
- );
- $this->ci->session->set_userdata($data);
- return TRUE;
- } else {
- // If the user is not logged in, FALSE must be returned
- // An attempt log could be executed here
- return FALSE;
- }
- }
- function logout()
- {
- $this->ci->session->set_userdata(array('user_id' => '', 'username' => '', 'status' => '','logged_in' => ''));
- $this->ci->session->sess_destroy();
- return TRUE;
- }
- function is_logged_in()
- {
- return $this->ci->session->userdata('user_id');
- }
- }
Add Comment
Please, Sign In to add comment