Bug #80297 [Com]: password_verify won't work with double quotes

From: Date: Fri, 30 Oct 2020 07:31:29 +0000
Subject: Bug #80297 [Com]: password_verify won't work with double quotes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230027@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80297&edit=1

 ID:                 80297
 Comment by:         heiglandreas@php.net
 Reported by:        brennen at swedecreek dot com
 Summary:            password_verify won't work with double quotes
 Status:             Not a bug
 Type:               Bug
 Package:            *Encryption and hash functions
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Just for clarification: The only thing that needs to be escaped is the 3rd "$" as the
first two are not starting a variable as the $ is immediately followed by a number which is not
allowed as the first character of a variable name.

So if you have to use double quotes you need to at least write it like this:

if(password_verify("helloworld",
"$2y$10\$nqqnTXGG/W4kNWDQ6Zlx8uNbduUfYmn/iS7eKOj9fbG6iVa.3dOAi")) {
  echo "Success";
}
else {
  echo "Fail";
}


But for the sake of explicitness (and my own sanity) I would always use single quotes unless I
explicitly want variable replacement to actually happen within the string.


Previous Comments:
------------------------------------------------------------------------
[2020-10-29 19:54:35] peehaa@php.net

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

------------------------------------------------------------------------
[2020-10-29 18:55:16] rtrtrtrtrt at dfdfdfdf dot dfd

php > if(password_verify("helloworld",
"\$2y\$10\$nqqnTXGG/W4kNWDQ6Zlx8uNbduUfYmn/iS7eKOj9fbG6iVa.3dOAi")) {echo
"Success";} else {echo "Fail";}
Success
php >

------------------------------------------------------------------------
[2020-10-29 18:54:18] rtrtrtrtrt at dfdfdfdf dot dfd

because you lack basics and proper error-reporting
in double quotes you need to secape $ as \$

----------------

Interactive shell

php > if(password_verify("helloworld",
"$2y$10$nqqnTXGG/W4kNWDQ6Zlx8uNbduUfYmn/iS7eKOj9fbG6iVa.3dOAi")) {echo
"Success";} else {echo "Fail";}

Notice: Undefined variable: nqqnTXGG in php shell code on line 1
Fail

------------------------------------------------------------------------
[2020-10-29 18:50:49] brennen at swedecreek dot com

Description:
------------
When using double quotes around $hash in password_verify, it always returns false. You have to use
double quotes.

Test script:
---------------
if(password_verify("helloworld",
"$2y$10$nqqnTXGG/W4kNWDQ6Zlx8uNbduUfYmn/iS7eKOj9fbG6iVa.3dOAi")) {
  echo "Success";
}
else {
  echo "Fail";
}

Expected result:
----------------
Success

Actual result:
--------------
Fail


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80297&edit=1


Thread (5 messages)

« previous php.bugs (#230027) next »