<?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 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.password-needs-rehash.php',
    1 => 'password_needs_rehash',
    2 => '&Uuml;berpr&uuml;ft, ob der &uuml;bergebene Hash mit den &uuml;bergebenen Optionen &uuml;bereinstimmt',
  ),
  'up' => 
  array (
    0 => 'ref.password.php',
    1 => 'Passwort-Hashing-Funktionen',
  ),
  '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' => 'de',
    '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">
   Überprüft, ob der übergebene Hash mit den übergebenen Optionen übereinstimmt
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.password-needs-rehash-description">
  <h3 class="title">Beschreibung</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">
   Diese Funktion überprüft, ob der übergebene Hash den gleichen Algorithmus
   und die gleichen Optionen nutzt, wie in den übergebenen Optionen abgegeben.
   Falls nicht, wird angenommen, dass erneutes Hashen notwendig ist.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.password-needs-rehash-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <dl>
   
    <dt><code class="parameter">hash</code></dt>
    <dd>
     <p class="para">
      Ein Hash, der durch <span class="function"><a href="function.password-hash.php" class="function">password_hash()</a></span> erzeugt wurde.
     </p>
    </dd>
   
   
    <dt><code class="parameter">algo</code></dt>
    <dd>
     <p class="para">
      Eine Konstante für den <a href="password.constants.php" class="link">Passwort-Algorithmus</a>, die den Algorithmus zum hashen des Passwortes angibt.
     </p>
    </dd>
   
   
    <dt><code class="parameter">options</code></dt>
    <dd>
     <p class="para">
      Ein assoziatives Array mit Optionen. Siehe auch <a href="password.constants.php" class="link">Konstanten für Passwort-Algorithmen</a> für Informationen zu den von den jeweiligen Algorithmen unterstützten Optionen.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.password-needs-rehash-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Gibt <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> zurück, falls der Hash erneut gehasht werden muss, damit die
   übergebenen Parameter <code class="parameter">algo</code> und
   <code class="parameter">options</code> übereinstimmen, sonst <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.password-needs-rehash-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Beschreibung</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.4.0</td>
       <td>
        Der Parameter <code class="parameter">algo</code> erwartet nun einen <a href="language.types.string.php" class="link">String</a>,
        akzeptiert aber aus Gründen der Abwärtskompatibilität noch immer
        <a href="language.types.integer.php" class="link">Integer</a>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.password-needs-rehash-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 Die Verwendung von <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">// Der Aufwand-Parameter cost von bcrypt kann sich im Lauf der Zeit ändern,<br />// da die Hardware besser wird<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">// Überprüfe den gespeicherten Hash gegen das Klartextkennwort<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">// Prüfe, ob sich der Algorithmus oder die Optionen geändert haben.<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">// Falls ja, dann erzeuge einen neuen Hash und ersetze den alten<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">// Aktualisiere den Benutzerdatensatz mit dem $newHash<br />    </span><span style="color: #007700">}<br /><br />    </span><span style="color: #FF8000">// Führe die Anmeldung durch.<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); ?>