Skip to content

Commit

Permalink
Merge pull request #10 from drugar101/master
Browse files Browse the repository at this point in the history
Minor update that maybe of interest
  • Loading branch information
Adam Griffiths committed Jul 26, 2011
2 parents e294531 + 4860f19 commit d78a322
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
5 changes: 5 additions & 0 deletions config/auth.php
Expand Up @@ -28,6 +28,11 @@
*/
$config['auth_login'] = 'admin/dashboard';

/**
* The default URI string to redirect to after a successful logout.
*/
$config['auth_logout'] = 'login';

/**
* The URI string to redirect to when a user entered incorrect login details or is not authenticated
*/
Expand Down
40 changes: 15 additions & 25 deletions libraries/Auth.php
Expand Up @@ -169,10 +169,15 @@ function login($redirect = NULL)
*
* @access public
*/
function logout()
function logout($redirect = NULL)
{
if($redirect === NULL)
{
$redirect = $this->config['auth_logout'];
}

$this->CI->session->sess_destroy();
$this->view('logout');
redirect($redirect);
} // function logout()


Expand Down Expand Up @@ -332,7 +337,7 @@ function _verify_details($auth_type, $username, $password)


/**
* Generate a new token/identifier from random.org
* Generate a new token/identifier
*
* @access private
* @param string
Expand All @@ -341,28 +346,13 @@ function _generate()
{
$username = $this->CI->session->userdata('username');

$rand_url = 'http://random.org/strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new';

if (ini_get('allow_url_fopen')) {
// Grab the random string using the easy version if we can
$token_source = fopen($rand_url, "r");
$token = fread($token_source, 20);
} elseif (function_exists('curl_version')) {
// No easy version, so try cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $rand_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$token = curl_exec($ch);
curl_close($ch);
} else {
// No love either way, generate a random string ourselves
$length = 20;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$token = ”;
for ($i = 0; $i < $length; $i++) {
$token .= $characters[mt_rand(0, strlen($characters)-1)];
}
}
// Generate a random string ourselves
$length = 20;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$token = ”;
for ($i = 0; $i < $length; $i++) {
$token .= $characters[mt_rand(0, strlen($characters)-1)];
}

$identifier = $username . $token;
$identifier = $this->_salt($identifier);
Expand Down

0 comments on commit d78a322

Please sign in to comment.