mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-26 19:29:58 +03:00
PHP7 compatibility, use PasswordHash from Wordpress 4.4 (PHP5+ constructor)
This commit is contained in:
parent
8cd9c6602c
commit
5bfb51c0ec
1 changed files with 40 additions and 17 deletions
|
@ -1,18 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
#
|
/**
|
||||||
# Portable PHP password hashing framework.
|
* Portable PHP password hashing framework.
|
||||||
#
|
* @package phpass
|
||||||
# Version 0.3 / genuine.
|
* @since 2.5.0
|
||||||
|
* @version 0.3 / WordPress
|
||||||
|
* @link http://www.openwall.com/phpass/
|
||||||
|
*/
|
||||||
|
|
||||||
#
|
#
|
||||||
# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
|
# Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
|
||||||
# the public domain. Revised in subsequent years, still public domain.
|
# the public domain. Revised in subsequent years, still public domain.
|
||||||
#
|
#
|
||||||
# There's absolutely no warranty.
|
# There's absolutely no warranty.
|
||||||
#
|
#
|
||||||
# The homepage URL for this framework is:
|
|
||||||
#
|
|
||||||
# http://www.openwall.com/phpass/
|
|
||||||
#
|
|
||||||
# Please be sure to update the Version line if you edit this file in any way.
|
# Please be sure to update the Version line if you edit this file in any way.
|
||||||
# It is suggested that you leave the main version number intact, but indicate
|
# It is suggested that you leave the main version number intact, but indicate
|
||||||
# your project name (after the slash) and add your own revision information.
|
# your project name (after the slash) and add your own revision information.
|
||||||
|
@ -24,13 +24,25 @@
|
||||||
# Obviously, since this code is in the public domain, the above are not
|
# Obviously, since this code is in the public domain, the above are not
|
||||||
# requirements (there can be none), but merely suggestions.
|
# requirements (there can be none), but merely suggestions.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Portable PHP password hashing framework.
|
||||||
|
*
|
||||||
|
* @package phpass
|
||||||
|
* @version 0.3 / WordPress
|
||||||
|
* @link http://www.openwall.com/phpass/
|
||||||
|
* @since 2.5.0
|
||||||
|
*/
|
||||||
class PasswordHash {
|
class PasswordHash {
|
||||||
var $itoa64;
|
var $itoa64;
|
||||||
var $iteration_count_log2;
|
var $iteration_count_log2;
|
||||||
var $portable_hashes;
|
var $portable_hashes;
|
||||||
var $random_state;
|
var $random_state;
|
||||||
|
|
||||||
function PasswordHash($iteration_count_log2, $portable_hashes)
|
/**
|
||||||
|
* PHP5 constructor.
|
||||||
|
*/
|
||||||
|
function __construct( $iteration_count_log2, $portable_hashes )
|
||||||
{
|
{
|
||||||
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||||
|
|
||||||
|
@ -40,15 +52,20 @@ class PasswordHash {
|
||||||
|
|
||||||
$this->portable_hashes = $portable_hashes;
|
$this->portable_hashes = $portable_hashes;
|
||||||
|
|
||||||
$this->random_state = microtime();
|
$this->random_state = microtime() . uniqid(rand(), TRUE); // removed getmypid() for compatibility reasons
|
||||||
if (function_exists('getmypid'))
|
}
|
||||||
$this->random_state .= getmypid();
|
|
||||||
|
/**
|
||||||
|
* PHP4 constructor.
|
||||||
|
*/
|
||||||
|
public function PasswordHash( $iteration_count_log2, $portable_hashes ) {
|
||||||
|
self::__construct( $iteration_count_log2, $portable_hashes );
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_random_bytes($count)
|
function get_random_bytes($count)
|
||||||
{
|
{
|
||||||
$output = '';
|
$output = '';
|
||||||
if (@is_readable('/dev/urandom') &&
|
if ( @is_readable('/dev/urandom') &&
|
||||||
($fh = @fopen('/dev/urandom', 'rb'))) {
|
($fh = @fopen('/dev/urandom', 'rb'))) {
|
||||||
$output = fread($fh, $count);
|
$output = fread($fh, $count);
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
|
@ -207,6 +224,10 @@ class PasswordHash {
|
||||||
|
|
||||||
function HashPassword($password)
|
function HashPassword($password)
|
||||||
{
|
{
|
||||||
|
if ( strlen( $password ) > 4096 ) {
|
||||||
|
return '*';
|
||||||
|
}
|
||||||
|
|
||||||
$random = '';
|
$random = '';
|
||||||
|
|
||||||
if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
|
if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
|
||||||
|
@ -242,12 +263,14 @@ class PasswordHash {
|
||||||
|
|
||||||
function CheckPassword($password, $stored_hash)
|
function CheckPassword($password, $stored_hash)
|
||||||
{
|
{
|
||||||
|
if ( strlen( $password ) > 4096 ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$hash = $this->crypt_private($password, $stored_hash);
|
$hash = $this->crypt_private($password, $stored_hash);
|
||||||
if ($hash[0] == '*')
|
if ($hash[0] == '*')
|
||||||
$hash = crypt($password, $stored_hash);
|
$hash = crypt($password, $stored_hash);
|
||||||
|
|
||||||
return $hash == $stored_hash;
|
return $hash === $stored_hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue