Skip to content
Snippets Groups Projects
Unverified Commit d4424692 authored by valunf's avatar valunf Committed by GitHub
Browse files

Added rounds support for sha512

 sha512 now supports hashes for salt started with "rounds=5000$"
parent 48ca2703
No related branches found
No related tags found
No related merge requests found
......@@ -69,9 +69,10 @@ class PassHash {
} elseif(preg_match('/^:B:(.+?):.{32}$/', $hash, $m)) {
$method = 'mediawiki';
$salt = $m[1];
} elseif(preg_match('/^\$6\$(.+?)\$/', $hash, $m)) {
} elseif(preg_match('/^\$6\$(rounds=\d+)?\$?(.+?)\$/', $hash, $m)) {
$method = 'sha512';
$salt = $m[1];
$salt = $m[2];
$magic = $m[1];
} elseif($len == 32) {
$method = 'md5';
} elseif($len == 40) {
......@@ -552,15 +553,20 @@ class PassHash {
*
* @param string $clear The clear text to hash
* @param string $salt The salt to use, null for random
* @param string $magic The rounds for sha512 (for example "rounds=3000"), null for default value
* @return string Hashed password
* @throws Exception
*/
public function hash_sha512($clear, $salt = null) {
public function hash_sha512($clear, $salt = null, $magic = null) {
if(!defined('CRYPT_SHA512') || CRYPT_SHA512 != 1) {
throw new Exception('This PHP installation has no SHA512 support');
}
$this->init_salt($salt, 8, false);
return crypt($clear, '$6$'.$salt.'$');
if(is_null($magic)) {
return crypt($clear, '$6$'.$salt.'$');
}else{
return crypt($clear, '$6$'.$magic.'$'.$salt.'$');
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment