Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Symfony/Component/Security/Core/Util/StringUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* String utility functions.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class StringUtils
{
Expand All @@ -35,6 +36,11 @@ private function __construct() {}
*/
public static function equals($knownString, $userInput)
{
// Use hash_equals if applicable
if (function_exists('hash_equals') && strlen($knownString) === strlen($userInput)) {
return hash_equals($knownString, $userInput);
}

// Prevent issues if string length is 0
$knownString .= chr(0);
$userInput .= chr(0);
Expand Down