svn: /phpdoc/en/trunk/reference/password/functions/ password-needs-rehash.xml

From: Date: Mon, 02 Mar 2015 22:50:57 +0000
Subject: svn: /phpdoc/en/trunk/reference/password/functions/ password-needs-rehash.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-13120@lists.php.net to get a copy of this message
ircmaxell Mon, 02 Mar 2015 22:50:57 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=336027 Log: Add example for password_needs_rehash to documentation. Changed paths: U phpdoc/en/trunk/reference/password/functions/password-needs-rehash.xml Modified: phpdoc/en/trunk/reference/password/functions/password-needs-rehash.xml =================================================================== --- phpdoc/en/trunk/reference/password/functions/password-needs-rehash.xml 2015-03-02 18:04:08 UTC (rev 336026) +++ phpdoc/en/trunk/reference/password/functions/password-needs-rehash.xml 2015-03-02 22:50:57 UTC (rev 336027) @@ -51,7 +51,41 @@ </varlistentry> </variablelist> </refsect1> + + <refsect1 role="examples"> + &reftitle.examples; + <para> + <example> + <title>Example #1 <function>password_needs_rehash()</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php +$password = 'rasmuslerdorf'; +$hash = '$2y$10$YCFsG6elYca568hBi2pZ0.3LDL5wjgxct1N8w/oLR/jfHsiQwCqTS'; + +// The cost parameter can change over time as hardware improves +$options = array('cost' => 11); + +// Verify stored hash against plain-text password +if (password_verify($password, $hash)) { + // Check if a newer hashing algorithm is available + // or the cost has changed + if (password_needs_rehash($hash, PASSWORD_DEFAULT, $options)) { + // If so, create a new hash, and replace the old one + $newHash = password_hash($password, PASSWORD_DEFAULT, $options); + } + + // Log user in +} +?> +]]> + </programlisting> + &example.outputs.similar; + </example> + </para> + </refsect1> + <refsect1 role="returnvalues"> &reftitle.returnvalues; <para>

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