X-Git-Url: https://git.cyclocoop.org/%242?a=blobdiff_plain;f=includes%2Fpassword%2FPbkdf2Password.php;h=4a8831e32f1e2d8a5e44968aeff1ba20fe04cdc3;hb=689c847a32e7fe8a0b3a559a88a627a252c5018e;hp=8ef6f8de280b9de5c657ab652d92b89ebc5ff35e;hpb=c340c41b37b5079ba90489f6b212bb8e4642031a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/password/Pbkdf2Password.php b/includes/password/Pbkdf2Password.php index 8ef6f8de28..4a8831e32f 100644 --- a/includes/password/Pbkdf2Password.php +++ b/includes/password/Pbkdf2Password.php @@ -41,12 +41,17 @@ class Pbkdf2Password extends ParameterizedPassword { return ':'; } + protected function shouldUseHashExtension() { + return isset( $this->config['use-hash-extension'] ) ? + $this->config['use-hash-extension'] : function_exists( 'hash_pbkdf2' ); + } + public function crypt( $password ) { if ( count( $this->args ) == 0 ) { $this->args[] = base64_encode( MWCryptRand::generate( 16, true ) ); } - if ( function_exists( 'hash_pbkdf2' ) ) { + if ( $this->shouldUseHashExtension() ) { $hash = hash_pbkdf2( $this->params['algo'], $password, @@ -55,8 +60,15 @@ class Pbkdf2Password extends ParameterizedPassword { (int)$this->params['length'], true ); + if ( !is_string( $hash ) ) { + throw new PasswordError( 'Error when hashing password.' ); + } } else { - $hashLen = strlen( hash( $this->params['algo'], '', true ) ); + $hashLenHash = hash( $this->params['algo'], '', true ); + if ( !is_string( $hashLenHash ) ) { + throw new PasswordError( 'Error when hashing password.' ); + } + $hashLen = strlen( $hashLenHash ); $blockCount = ceil( $this->params['length'] / $hashLen ); $hash = '';