Skip to content

Commit

Permalink
Changed cookie access to use CodeIgniter input class instead of direc…
Browse files Browse the repository at this point in the history
…t access
  • Loading branch information
jacobtomlinson committed Jun 2, 2014
1 parent ca5d616 commit 534d5ca
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions application/libraries/Aauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ public function __construct() {
public function login($email, $pass, $remember = FALSE) {

// remove cookies first
setcookie("user", "", time()-3600, '/');
$cookie = array(
'name' => 'user',
'value' => '',
'expire' => time()-3600,
'path' => '/',
);

$this->CI->input->set_cookie($cookie);

if( !valid_email($email) or !ctype_alnum($pass) or strlen($pass) < 5 or strlen($pass) > $this->config_vars['max'] ) {
$this->error($this->config_vars['wrong']);
Expand Down Expand Up @@ -95,7 +102,14 @@ public function login($email, $pass, $remember = FALSE) {
$random_string = random_string('alnum', 16);
$this->update_remember($row->id, $random_string, $remember_date );

setcookie( 'user', $row->id . "-" . $random_string, time() + 99*999*999, '/');
$cookie = array(
'name' => 'user',
'value' => $row->id . "-" . $random_string,
'expire' => time() + 99*999*999,
'path' => '/',
);

$this->CI->input->set_cookie($cookie);
}

// update last login
Expand Down Expand Up @@ -143,10 +157,10 @@ public function is_loggedin() {
{return true;}

else{
if( !array_key_exists('user', $_COOKIE) ){
if( !$this->CI->input->cookie('user', TRUE) ){
return false;
}else{
$cookie = explode('-', $_COOKIE['user']);
$cookie = explode('-', $this->CI->input->cookie('user', TRUE));
if(!is_numeric( $cookie[0] ) or strlen($cookie[1]) < 13 ){return false;}
else{
$query = $this->CI->db->where('id', $cookie[0]);
Expand Down

0 comments on commit 534d5ca

Please sign in to comment.