mirror of
https://github.com/Combodo/iTop.git
synced 2026-09-18 23:49:14 +02:00
ormPassword: allow use of different password hash algo
This commit is contained in:
@@ -1495,6 +1495,11 @@ class Config
|
||||
*/
|
||||
protected $m_aCharsets;
|
||||
|
||||
/**
|
||||
* @var array Password hash algorithm to use.
|
||||
*/
|
||||
protected $m_iPasswordHashAlgo;
|
||||
|
||||
/**
|
||||
* Config constructor.
|
||||
*
|
||||
@@ -1538,6 +1543,7 @@ class Config
|
||||
$this->m_sExtAuthVariable = DEFAULT_EXT_AUTH_VARIABLE;
|
||||
$this->m_aCharsets = array();
|
||||
$this->m_bQueryCacheEnabled = DEFAULT_QUERY_CACHE_ENABLED;
|
||||
$this->m_iPasswordHashAlgo = PASSWORD_DEFAULT;
|
||||
|
||||
//define default encryption params according to php install
|
||||
$aEncryptParams = SimpleCrypt::GetNewDefaultParams();
|
||||
@@ -1697,6 +1703,7 @@ class Config
|
||||
$this->m_sEncryptionKey = isset($MySettings['encryption_key']) ? trim($MySettings['encryption_key']) : $this->m_sEncryptionKey;
|
||||
$this->m_sEncryptionLibrary = isset($MySettings['encryption_library']) ? trim($MySettings['encryption_library']) : $this->m_sEncryptionLibrary;
|
||||
$this->m_aCharsets = isset($MySettings['csv_import_charsets']) ? $MySettings['csv_import_charsets'] : array();
|
||||
$this->m_iPasswordHashAlgo = isset($MySettings['password_hash_algo']) ? $MySettings['password_hash_algo'] : $this->m_iPasswordHashAlgo;
|
||||
}
|
||||
|
||||
protected function Verify()
|
||||
@@ -1852,6 +1859,11 @@ class Config
|
||||
return $this->m_aCharsets;
|
||||
}
|
||||
|
||||
public function GetPasswordHashAlgo()
|
||||
{
|
||||
return $this->m_iPasswordHashAlgo;
|
||||
}
|
||||
|
||||
public function SetLogGlobal($iLogGlobal)
|
||||
{
|
||||
$this->m_iLogGlobal = $iLogGlobal;
|
||||
@@ -1967,6 +1979,7 @@ class Config
|
||||
$aSettings['encryption_key'] = $this->m_sEncryptionKey;
|
||||
$aSettings['encryption_library'] = $this->m_sEncryptionLibrary;
|
||||
$aSettings['csv_import_charsets'] = $this->m_aCharsets;
|
||||
$aSettings['password_hash_algo'] = $this->m_iPasswordHashAlgo;
|
||||
|
||||
foreach ($this->m_aModuleSettings as $sModule => $aProperties)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,8 @@ class ormPassword
|
||||
*/
|
||||
public function SetPassword($sClearTextPassword)
|
||||
{
|
||||
$this->m_sHashed = password_hash($sClearTextPassword, PASSWORD_DEFAULT);
|
||||
$iHashAlgo = MetaModel::GetConfig()->GetPasswordHashAlgo();
|
||||
$this->m_sHashed = password_hash($sClearTextPassword, $iHashAlgo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,18 +97,18 @@ class ormPassword
|
||||
{
|
||||
$bResult = false;
|
||||
$aInfo = password_get_info($this->m_sHashed);
|
||||
switch ($aInfo["algo"])
|
||||
if (is_null($aInfo["algo"]) || $aInfo["algo"] === 0)
|
||||
{
|
||||
case 0:
|
||||
//unknown, assume it's a legacy password
|
||||
$sHashedPwd = $this->ComputeHash($sClearTextPassword);
|
||||
if ($this->m_sHashed == $sHashedPwd)
|
||||
{
|
||||
$bResult = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$bResult = password_verify($sClearTextPassword, $this->m_sHashed);
|
||||
//unknown, assume it's a legacy password
|
||||
$sHashedPwd = $this->ComputeHash($sClearTextPassword);
|
||||
if ($this->m_sHashed == $sHashedPwd)
|
||||
{
|
||||
$bResult = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$bResult = password_verify($sClearTextPassword, $this->m_sHashed);
|
||||
}
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user