Sophie

Sophie

distrib > Mageia > 7 > aarch64 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 5528

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Checks if the given hash matches the given options</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.password-hash.html">password_hash</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.password-verify.html">password_verify</a></div>
 <div class="up"><a href="ref.password.html">Password Hashing Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.password-needs-rehash" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">password_needs_rehash</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7)</p><p class="refpurpose"><span class="refname">password_needs_rehash</span> &mdash; <span class="dc-title">Checks if the given hash matches the given options</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.password-needs-rehash-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>password_needs_rehash</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$hash</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$algo</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   This function checks to see if the supplied hash implements the algorithm
   and options provided. If not, it is assumed that the hash needs to be
   rehashed.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.password-needs-rehash-parameters">
  <h3 class="title">Parameters</h3>
  <dl>

   
    <dt>
<code class="parameter">hash</code></dt>

    <dd>

     <p class="para">
      A hash created by <span class="function"><a href="function.password-hash.html" class="function">password_hash()</a></span>.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">algo</code></dt>

    <dd>

     <p class="para">
      A <a href="password.constants.html" class="link">password algorithm constant</a> denoting the algorithm to use when hashing the password.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">options</code></dt>

    <dd>

     <p class="para">
      An associative array containing options. See the <a href="password.constants.html" class="link">password algorithm constants</a> for documentation on the supported options for each algorithm.
     </p>
    </dd>

   
  </dl>

 </div>

 
 <div class="refsect1 examples" id="refsect1-function.password-needs-rehash-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-995">
    <p><strong>Example #1 Usage of <span class="function"><strong>password_needs_rehash()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'rasmuslerdorf'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hash&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'$2y$10$YCFsG6elYca568hBi2pZ0.3LDL5wjgxct1N8w/oLR/jfHsiQwCqTS'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;The&nbsp;cost&nbsp;parameter&nbsp;can&nbsp;change&nbsp;over&nbsp;time&nbsp;as&nbsp;hardware&nbsp;improves<br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'cost'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">11</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Verify&nbsp;stored&nbsp;hash&nbsp;against&nbsp;plain-text&nbsp;password<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">password_verify</span><span style="color: #007700">(</span><span style="color: #0000BB">$password</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$hash</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Check&nbsp;if&nbsp;a&nbsp;newer&nbsp;hashing&nbsp;algorithm&nbsp;is&nbsp;available<br />&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;or&nbsp;the&nbsp;cost&nbsp;has&nbsp;changed<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">password_needs_rehash</span><span style="color: #007700">(</span><span style="color: #0000BB">$hash</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PASSWORD_DEFAULT</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;If&nbsp;so,&nbsp;create&nbsp;a&nbsp;new&nbsp;hash,&nbsp;and&nbsp;replace&nbsp;the&nbsp;old&nbsp;one<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$newHash&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">password_hash</span><span style="color: #007700">(</span><span style="color: #0000BB">$password</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PASSWORD_DEFAULT</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Log&nbsp;user&nbsp;in<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p> 
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.password-needs-rehash-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> if the hash should be rehashed to match the given
   <code class="parameter">algo</code> and <code class="parameter">options</code>, or <strong><code>FALSE</code></strong>
   otherwise.
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.password-hash.html">password_hash</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.password-verify.html">password_verify</a></div>
 <div class="up"><a href="ref.password.html">Password Hashing Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>