svn: /phpdoc/en/trunk/ appendices/migration56/new-features.xml reference/strings/functions/crypt.xml

From: Date: Thu, 28 Aug 2014 03:45:57 +0000
Subject: svn: /phpdoc/en/trunk/ appendices/migration56/new-features.xml reference/strings/functions/crypt.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-12737@lists.php.net to get a copy of this message
aharvey Thu, 28 Aug 2014 03:45:57 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=334629 Log: Suggest hash_equals() on the crypt() page. Changed paths: U phpdoc/en/trunk/appendices/migration56/new-features.xml U phpdoc/en/trunk/reference/strings/functions/crypt.xml Modified: phpdoc/en/trunk/appendices/migration56/new-features.xml =================================================================== --- phpdoc/en/trunk/appendices/migration56/new-features.xml 2014-08-28 03:39:10 UTC (rev 334628) +++ phpdoc/en/trunk/appendices/migration56/new-features.xml 2014-08-28 03:45:57 UTC (rev 334629) @@ -284,8 +284,6 @@ attacks). </para> - <!-- TODO: update crypt() examples --> - <informalexample> <programlisting role="php"> <![CDATA[ Modified: phpdoc/en/trunk/reference/strings/functions/crypt.xml =================================================================== --- phpdoc/en/trunk/reference/strings/functions/crypt.xml 2014-08-28 03:39:10 UTC (rev 334628) +++ phpdoc/en/trunk/reference/strings/functions/crypt.xml 2014-08-28 03:45:57 UTC (rev 334629) @@ -155,6 +155,14 @@ Returns the hashed string or a string that is shorter than 13 characters and is guaranteed to differ from the salt on failure. </para> + <warning> + <simpara> + When validating passwords, a string comparison function that isn't + vulnerable to timing attacks should be used to compare the output of + <function>crypt</function> to the previously known hash. PHP 5.6 onwards + provides <function>hash_equals</function> for this purpose. + </simpara> + </warning> </refsect1> <refsect1 role="changelog"> @@ -224,7 +232,7 @@ password, to avoid problems when different hashing algorithms are used. (As it says above, standard DES-based password hashing uses a 2-character salt, but MD5-based hashing uses 12.) */ -if (crypt($user_input, $hashed_password) == $hashed_password) { +if (hash_equals($hashed_password, crypt($user_input, $hashed_password)) { echo "Password verified!"; } ?> @@ -312,6 +320,7 @@ &reftitle.seealso; <para> <simplelist> + <member><function>hash_equals</function></member> <member><function>password_hash</function></member> <member><function>md5</function></member> <member>The <link linkend="ref.mcrypt">Mcrypt</link> extension</member>

« previous php.doc.cvs (#12737) next »