Skip to content

Commit 0dc7efb

Browse files
author
André R
authored
[2019.03] Some fixes for MySQL8 and PHP7.3 (#1430)
* [Mysql8] Add support to login when using Mysql8 Removes mysql PASSWORD usage away from the initial always used sql for looking for mathcing users. The deprecated Mysql password hash type will still work, just less efficient. But as PASSWORD() sql function is removed in Mysql8 it won't work there. * [PHP73] Silence notices on compact usage in compiled templates * Add note on PASSWORD_HASH_MYSQL saying it won't work on MySQL 8.0 * Update ezuser.php
1 parent 2493420 commit 0dc7efb

File tree

3 files changed

+14
-30
lines changed

3 files changed

+14
-30
lines changed

kernel/classes/datatypes/ezuser/ezuser.php

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class eZUser extends eZPersistentObject
2626
/// MD5 of site, user and password
2727
const PASSWORD_HASH_MD5_SITE = 3;
2828
/// Legacy support for mysql hashed passwords
29+
/// NB! Does not work as of MySQL 8.0 where this has been removed from MySQL.
2930
const PASSWORD_HASH_MYSQL = 4;
3031
/// Passwords in plaintext, should not be used for real sites
3132
const PASSWORD_HASH_PLAINTEXT = 5;
@@ -855,31 +856,13 @@ protected static function _loginUser( $login, $password, $authenticationMatch =
855856

856857
$contentObjectStatus = eZContentObject::STATUS_PUBLISHED;
857858

858-
$ini = eZINI::instance();
859-
$databaseName = $db->databaseName();
860-
// if mysql
861-
if ( $databaseName === 'mysql' )
862-
{
863-
$query = "SELECT contentobject_id, password_hash, password_hash_type, email, login
864-
FROM ezuser, ezcontentobject
865-
WHERE ( $loginText ) AND
866-
ezcontentobject.status='$contentObjectStatus' AND
867-
ezcontentobject.id=contentobject_id AND
868-
password_hash_type!=0 AND
869-
( ( password_hash_type!=4 ) OR
870-
( password_hash_type=4 AND
871-
password_hash=PASSWORD('$passwordEscaped') ) )";
872-
}
873-
else
874-
{
875-
$query = "SELECT contentobject_id, password_hash,
876-
password_hash_type, email, login
877-
FROM ezuser, ezcontentobject
878-
WHERE ( $loginText )
879-
AND password_hash_type!=0
880-
AND ezcontentobject.status='$contentObjectStatus'
881-
AND ezcontentobject.id=contentobject_id";
882-
}
859+
// PASSWORD_HASH_MYSQL is handled further down as this inital SQL needs to work on MySQL 8.0 as well as PostgreSQL
860+
$query = "SELECT contentobject_id, password_hash, password_hash_type, email, login
861+
FROM ezuser, ezcontentobject
862+
WHERE ( $loginText )
863+
AND password_hash_type!=0
864+
AND ezcontentobject.status='$contentObjectStatus'
865+
AND ezcontentobject.id=contentobject_id";
883866

884867
$users = $db->arrayQuery( $query );
885868
$exists = false;
@@ -895,6 +878,7 @@ protected static function _loginUser( $login, $password, $authenticationMatch =
895878
$hashType,
896879
$hash );
897880

881+
$databaseName = $db->databaseName();
898882
// If hash type is MySql
899883
if ( $hashType == self::PASSWORD_HASH_MYSQL and $databaseName === 'mysql' )
900884
{

lib/eztemplate/classes/eztemplateforeachfunction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ function templateNodeTransformation( $functionName, &$node,
126126
$variableStack = "fe_variable_stack_$uniqid";
127127
$namesArray = array( $array, $arrayKeys, $nItems, $nItemsProcessed, $i, $key, $val, $offset, $max, $reverse, $firstVal, $lastVal );
128128

129-
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( !isset( \$$variableStack ) ) \$$variableStack = array();" );
130-
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$" . $variableStack ."[] = compact( '" . implode( "', '", $namesArray ) . "' );" );
129+
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( !isset( \$$variableStack ) ) \$$variableStack = [];" );
130+
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$" . $variableStack ."[] = @compact( '" . implode( "', '", $namesArray ) . "' );" );
131131

132132
$newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameters['array'], $nodePlacement, array( 'text-result' => false ), $array );
133-
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$$arrayKeys = is_array( \$$array ) ? array_keys( \$$array ) : array();" );
133+
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$$arrayKeys = is_array( \$$array ) ? array_keys( \$$array ) : [];" );
134134
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$$nItems = count( \$$arrayKeys );" );
135135
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$$nItemsProcessed = 0;" );
136136

lib/eztemplate/classes/eztemplateforfunction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ function templateNodeTransformation( $functionName, &$node,
9494
$namesArray = array( "for_firstval_$uniqid", "for_lastval_$uniqid", "for_i_$uniqid" );
9595

9696
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "// for begins" );
97-
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( !isset( \$$variableStack ) ) \$$variableStack = array();" );
98-
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$" . $variableStack ."[] = compact( '" . implode( "', '", $namesArray ) . "' );" );
97+
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( !isset( \$$variableStack ) ) \$$variableStack = [];" );
98+
$newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$" . $variableStack ."[] = @compact( '" . implode( "', '", $namesArray ) . "' );" );
9999

100100
$newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameters['first_val'], $nodePlacement, array( 'treat-value-as-non-object' => true ), "for_firstval_$uniqid" );
101101
$newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameters['last_val'], $nodePlacement, array( 'treat-value-as-non-object' => true ), "for_lastval_$uniqid" );

0 commit comments

Comments
 (0)