Skip to content

Commit

Permalink
Move hash_password() out of the UserGroupStorage API.
Browse files Browse the repository at this point in the history
Parameterize which driver we use so that we can switch over to a new one.
  • Loading branch information
bharat committed Sep 30, 2009
1 parent 09f79c8 commit a7c04d0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 24 deletions.
4 changes: 3 additions & 1 deletion modules/user/helpers/user.php
Expand Up @@ -89,7 +89,9 @@ static function is_correct_password($user, $password) {
* @return string hashed password
*/
static function hash_password($password) {
return UserGroupStorage::instance()->hash_password($password);
require_once(MODPATH . "user/lib/PasswordHash.php");
$hashGenerator = new PasswordHash(10, true);
return $hashGenerator->HashPassword($password);
}

/**
Expand Down
12 changes: 2 additions & 10 deletions modules/user/libraries/UserGroupStorage.php
Expand Up @@ -37,7 +37,8 @@ static function &instance() {
* Sets up the storage configuration, loads the UserGroupStorage_Driver.
*/
public function __construct() {
$driver = "UserGroupStorage_Gallery3_Driver";
$driver = module::get_var("gallery", "user_group_storage", "Gallery3");
$driver = "UserGroupStorage_{$driver}_Driver";
if (!Kohana::auto_load($driver)) {
throw new Exception("@todo MISSING_STORAGE_DRIVER");
}
Expand Down Expand Up @@ -99,15 +100,6 @@ public function is_correct_password($user, $password) {
return $this->driver->is_correct_password($user, $password);
}

/**
* Create the hashed passwords.
* @param string $password a plaintext password
* @return string hashed password
*/
public function hash_password($password) {
return $this->driver->hash_password($password);
}

/**
* Log in as a given user.
* @param User_Model $user the user object.
Expand Down
7 changes: 0 additions & 7 deletions modules/user/libraries/drivers/UserGroupStorage.php
Expand Up @@ -61,13 +61,6 @@ abstract function create_user($name, $full_name, $password);
*/
abstract function is_correct_password($user, $password);

/**
* Create the hashed passwords.
* @param string $password a plaintext password
* @return string hashed password
*/
abstract function hash_password($password);

/**
* Log in as a given user.
* @param User_Model $user the user object.
Expand Down
6 changes: 0 additions & 6 deletions modules/user/libraries/drivers/UserGroupStorage/Gallery3.php
Expand Up @@ -108,12 +108,6 @@ public function is_correct_password($user, $password) {
return false;
}

public function hash_password($password) {
require_once(MODPATH . "user/lib/PasswordHash.php");
$hashGenerator = new PasswordHash(10, true);
return $hashGenerator->HashPassword($password);
}

public function login($user) {
$user->login_count += 1;
$user->last_login = time();
Expand Down

0 comments on commit a7c04d0

Please sign in to comment.