<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.password.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.password-needs-rehash.php',
    1 => 'password_needs_rehash',
    2 => 'Checks if the given hash matches the given options',
  ),
  'up' => 
  array (
    0 => 'ref.password.php',
    1 => 'Функції Хешування Пароля',
  ),
  'prev' => 
  array (
    0 => 'function.password-hash.php',
    1 => 'password_hash',
  ),
  'next' => 
  array (
    0 => 'function.password-verify.php',
    1 => 'password_verify',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/password/functions/password-needs-rehash.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<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, PHP 8)</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">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>password_needs_rehash</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$hash</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span> <code class="parameter">$algo</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$options</code><span class="initializer"> = []</span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></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">Параметри</h3>
  <dl>
   
    <dt><code class="parameter">hash</code></dt>
    <dd>
     <p class="para">
      Геш, створений функцією <span class="function"><a href="function.password-hash.php" class="function">password_hash()</a></span>.
     </p>
    </dd>
   
   
    <dt><code class="parameter">algo</code></dt>
    <dd>
     <p class="para">
      <a href="password.constants.php" class="link">Константа алгоритму для паролю</a>, що позначає алгоритм для гешування пароля.
     </p>
    </dd>
   
   
    <dt><code class="parameter">options</code></dt>
    <dd>
     <p class="para">
      Асоціативниий масив опцій. Документація щодо доступних опцій для кожного алгоритму викладена на сторінці <a href="password.constants.php" class="link">Константи алгоритмів для паролів</a>.
     </p>
    </dd>
   
  </dl>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.password-needs-rehash-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></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><a href="reserved.constants.php#constant.false">false</a></code></strong>
   otherwise.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.password-needs-rehash-changelog">
  <h3 class="title">Журнал змін</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Версія</th>
       <th>Опис</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.4.0</td>
       <td>
        The <code class="parameter">algo</code> parameter expects a <span class="type"><a href="language.types.string.php" class="type string">string</a></span> now, but still accepts
        <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>s for backward compatibility.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.password-needs-rehash-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #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 </span><span style="color: #007700">= </span><span style="color: #DD0000">'rasmuslerdorf'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hash </span><span style="color: #007700">= </span><span style="color: #DD0000">'$2y$12$4Umg0rCJwMswRw/l.SwHvuQV01coP0eWmGzd61QH2RvAOMANUBGC.'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$algorithm </span><span style="color: #007700">= </span><span style="color: #0000BB">PASSWORD_BCRYPT</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// bcrypt's cost parameter can change over time as hardware improves<br /></span><span style="color: #0000BB">$options </span><span style="color: #007700">= [</span><span style="color: #DD0000">'cost' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">13</span><span style="color: #007700">];<br /><br /></span><span style="color: #FF8000">// Verify stored hash against plain-text password<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">password_verify</span><span style="color: #007700">(</span><span style="color: #0000BB">$password</span><span style="color: #007700">, </span><span style="color: #0000BB">$hash</span><span style="color: #007700">)) {<br />    </span><span style="color: #FF8000">// Check if either the algorithm or the options have changed<br />    </span><span style="color: #007700">if (</span><span style="color: #0000BB">password_needs_rehash</span><span style="color: #007700">(</span><span style="color: #0000BB">$hash</span><span style="color: #007700">, </span><span style="color: #0000BB">$algorithm</span><span style="color: #007700">, </span><span style="color: #0000BB">$options</span><span style="color: #007700">)) {<br />        </span><span style="color: #FF8000">// If so, create a new hash, and replace the old one<br />        </span><span style="color: #0000BB">$newHash </span><span style="color: #007700">= </span><span style="color: #0000BB">password_hash</span><span style="color: #007700">(</span><span style="color: #0000BB">$password</span><span style="color: #007700">, </span><span style="color: #0000BB">$algorithm</span><span style="color: #007700">, </span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br />        </span><span style="color: #FF8000">// Update the user record with the $newHash<br />    </span><span style="color: #007700">}<br /><br />    </span><span style="color: #FF8000">// Perform the login.<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


</div><?php manual_footer($setup); ?>