Improvement hashPassword config

This commit is contained in:
Marco Antonio Nina
2014-10-02 14:56:20 -04:00
parent 929d5471e4
commit bd41c076bf
2 changed files with 30 additions and 32 deletions

View File

@@ -2860,29 +2860,46 @@ class Bootstrap
}
}
public function hasPassword($pass, $previous=false) {
$passEncrypt = md5($pass);
try {
require_once PATH_CORE .'methods' . PATH_SEP .'enterprise/enterprise.php';
$passEncrypt = enterprisePlugin::hashPassword($pass, $previous);
} catch (Exception $e) {
public function getConfigHashPassword()
{
G::LoadClass( "configuration" );
$config= new Configurations();
return $config->getConfiguration('ENTERPRISE_SETTING_ENCRYPT', '');
}
public function hashPassword($pass, $config = '', $includeHash = false, $hashOld = false)
{
$typeEncrypt = ($config != '') ? $config : Bootstrap::getConfigHashPassword();
$encrypt = 'md5';
if ($typeEncrypt != null) {
if (isset($typeEncrypt['current']) && $typeEncrypt['current'] != '') {
$encrypt = $typeEncrypt['current'];
}
if ($hashOld && isset($typeEncrypt['previous']) && $typeEncrypt['previous'] != '' ) {
$encrypt = $typeEncrypt['previous'];
}
}
if ($includeHash) {
$var = $encrypt . ':' . $pass;
} else {
eval("\$var = hash('" . $encrypt . "', '" . $pass . "');");
}
return $passEncrypt;
return $var;
}
public function verifyHashPassword ($pass, $userPass)
{
//$verify = Bootstrap::hasPassword($pass);
if (Bootstrap::hasPassword($pass) == $userPass) {
$config = Bootstrap::getConfigHashPassword();
if (Bootstrap::hashPassword($pass, $config) == $userPass
|| Bootstrap::hashPassword($pass, $config, true) == $userPass) {
return true;
}
if (Bootstrap::hasPassword($pass, true) == $userPass) {
if (Bootstrap::hashPassword($pass, $config, false, true) == $userPass
|| Bootstrap::hashPassword($pass, $config, true, true) == $userPass) {
return true;
}
return false;
}
}

View File

@@ -346,25 +346,6 @@ class enterprisePlugin extends PMPlugin
fclose($file);
}
}
public function hashPassword ($pass, $previous=false)
{
G::LoadClass( "configuration" );
$config= new Configurations();
$typeEncrypt = $config->getConfiguration('ENTERPRISE_SETTING_ENCRYPT', '');
$encrypt = 'md5';
if ($typeEncrypt != null) {
if (isset($typeEncrypt['current']) && $typeEncrypt['current'] != '') {
$encrypt = $typeEncrypt['current'];
}
if ($previous && isset($typeEncrypt['previous']) && $typeEncrypt['previous'] != '' ) {
$encrypt = $typeEncrypt['previous'];
}
}
eval("\$var = hash('" . $encrypt . "', '" . $pass . "');");
return $var;
}
}
$oPluginRegistry = &PMPluginRegistry::getSingleton();