various refactoring and tweaks.

This commit is contained in:
Taylor Otwell
2011-10-20 21:44:18 -05:00
parent df9130dafa
commit af36cb3d5a
22 changed files with 140 additions and 110 deletions

View File

@@ -1,6 +1,5 @@
<?php namespace Laravel\Security;
use Laravel\IoC;
use Laravel\Str;
use Laravel\Config;
use Laravel\Cookie;
@@ -42,7 +41,7 @@ class Auth {
/**
* Get the current user of the application.
*
* This method will call the "user" closure in the authentication configuration file.
* This method will call the "user" closure in the auth configuration file.
* If the user is not authenticated, null will be returned by the methd.
*
* If no user exists in the session, the method will check for a "remember me"
@@ -64,7 +63,9 @@ class Auth {
static::$user = call_user_func(Config::get('auth.user'), Session::get(Auth::user_key));
if (is_null(static::$user) and ! is_null($cookie = Cookie::get(Auth::remember_key)))
$cookie = Cookie::get(Auth::remember_key);
if (is_null(static::$user) and ! is_null($cookie))
{
static::$user = static::recall($cookie);
}
@@ -113,7 +114,9 @@ class Auth {
{
$config = Config::get('auth');
if ( ! is_null($user = call_user_func($config['attempt'], $username, $password, $config)))
$user = call_user_func($config['attempt'], $username, $password, $config);
if ( ! is_null($user))
{
static::login($user, $config, $remember);

View File

@@ -54,7 +54,9 @@ class Crypter {
$iv = mcrypt_create_iv(static::iv_size(), $randomizer);
return base64_encode($iv.mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv));
$value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv);
return base64_encode($iv.$value);
}
/**
@@ -67,20 +69,20 @@ class Crypter {
{
list($iv, $value) = static::parse(base64_decode($value, true));
return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0");
$value = mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv);
return rtrim($value, "\0");
}
/**
* Parse an encrypted value into the input vector and the actual value.
*
* If the given value is not valid base64 data, an exception will be thrown.
*
* @param string $value
* @return array
*/
protected static function parse($value)
{
if ( ! is_string($value))
if ($value === false)
{
throw new \Exception('Decryption error. Input value is not valid base64 data.');
}