Created
July 2, 2012 15:29
-
-
Save bmoore/3033798 to your computer and use it in GitHub Desktop.
The authentication library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Auth | |
{ | |
private $hasher; | |
private $session; | |
function __construct() | |
{ | |
$this->hasher = new PasswordHash(8, false); | |
} | |
function hash_password($password) | |
{ | |
return $this->hasher->HashPassword($password); | |
} | |
function check_password($password, $hash) | |
{ | |
$result = false; | |
if ($hash) { | |
$result = $this->hasher->CheckPassword($password, $hash); | |
} | |
return $result; | |
} | |
function set_logged_in($user_id) | |
{ | |
$this->load_session(); | |
$this->session->set_userdata('user_id', $user_id); | |
} | |
function is_logged_in() | |
{ | |
$this->load_session(); | |
return $this->session->userdata('user_id') > 0; | |
} | |
function get_user_id() | |
{ | |
$this->load_session(); | |
return $this->session->userdata('user_id'); | |
} | |
function set_logged_out() | |
{ | |
$this->load_session(); | |
$this->session->unset_userdata('user_id'); | |
} | |
private function load_session() | |
{ | |
if (!$this->session) { | |
$ci = get_instance(); | |
$this->session = $ci->session; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment