Skip to content

Commit

Permalink
Improve passwords hashing and testing
Browse files Browse the repository at this point in the history
* Fix issue with failed blowfish-based encryption (see second part of Issue #7)
* Switch to binary safe hashes comparison
  • Loading branch information
faf committed Sep 24, 2013
1 parent 239e62d commit 96e1f40
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/messenger/webim/libs/operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,31 +408,31 @@ function get_operator_groupids($operatorid)

function calculate_password_hash($login, $password)
{

$hash = '*0';
if (CRYPT_BLOWFISH == 1) {
if (defined('PHP_VERSION_ID') && (PHP_VERSION_ID > 50306)) {
return crypt($password, '$2y$08$' . $login);
$hash = crypt($password, '$2y$08$' . $login);
}
else {
return crypt($password, '$2a$08$' . $login);
$hash = crypt($password, '$2a$08$' . $login);
}
}
else if (CRYPT_MD5 == 1) {
return crypt($password, '$1$' . $login);

if ( (CRYPT_MD5 == 1) && !strcmp($hash, '*0') ) {
$hash = crypt($password, '$1$' . $login);
}

return md5($password);
return strcmp($hash, '*0') ? $hash : md5($password);
}

function check_password_hash($login, $password, $hash)
{
if (preg_match('/^\$/', $hash)) {
return (calculate_password_hash($login, $password) == $hash);
return !strcmp(calculate_password_hash($login, $password), $hash);
}
else {
return (md5($password) == $hash);
return !strcmp(md5($password), $hash);
}

}

?>

0 comments on commit 96e1f40

Please sign in to comment.