<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.sodium.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.sodium-crypto-pwhash-str.php',
    1 => 'sodium_crypto_pwhash_str',
    2 => 'Get an ASCII-encoded hash',
  ),
  'up' => 
  array (
    0 => 'ref.sodium.php',
    1 => 'Sodium Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.sodium-crypto-pwhash-scryptsalsa208sha256-str-verify.php',
    1 => 'sodium_crypto_pwhash_scryptsalsa208sha256_str_verify',
  ),
  'next' => 
  array (
    0 => 'function.sodium-crypto-pwhash-str-needs-rehash.php',
    1 => 'sodium_crypto_pwhash_str_needs_rehash',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/sodium/functions/sodium-crypto-pwhash-str.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.sodium-crypto-pwhash-str" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sodium_crypto_pwhash_str</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.2.0, PHP 8)</p><p class="refpurpose"><span class="refname">sodium_crypto_pwhash_str</span> &mdash; <span class="dc-title">Get an ASCII-encoded hash</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sodium-crypto-pwhash-str-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sodium_crypto_pwhash_str</strong></span>(<span class="methodparam"><span class="attribute"><a href="class.sensitiveparameter.php">#[\SensitiveParameter]</a> </span><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$password</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$opslimit</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$memlimit</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
Uses a CPU- and memory-hard hash algorithm along with a randomly-generated salt, and memory and CPU limits to generate an ASCII-encoded hash suitable for password storage.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sodium-crypto-pwhash-str-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">password</code></dt>
    <dd>
     <span class="simpara">
      <span class="type"><a href="language.types.string.php" class="type string">string</a></span>; The password to generate a hash for.
     </span>
    </dd>
   
   
    <dt><code class="parameter">opslimit</code></dt>
    <dd>
     <span class="simpara">
      Represents a maximum amount of computations to perform. Raising this number will make the function require more CPU cycles to compute a key. There are constants available to set the operations limit to appropriate values depending on intended use, in order of strength: <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-opslimit-interactive">SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE</a></code></strong>, <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-opslimit-moderate">SODIUM_CRYPTO_PWHASH_OPSLIMIT_MODERATE</a></code></strong> and <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-opslimit-sensitive">SODIUM_CRYPTO_PWHASH_OPSLIMIT_SENSITIVE</a></code></strong>.
     </span>
    </dd>
   
   
    <dt><code class="parameter">memlimit</code></dt>
    <dd>
     <span class="simpara">
      The maximum amount of RAM that the function will use, in bytes. There are constants to help you choose an appropriate value, in order of size: <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-memlimit-interactive">SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE</a></code></strong>, <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-memlimit-moderate">SODIUM_CRYPTO_PWHASH_MEMLIMIT_MODERATE</a></code></strong>, and <strong><code><a href="sodium.constants.php#constant.sodium-crypto-pwhash-memlimit-sensitive">SODIUM_CRYPTO_PWHASH_MEMLIMIT_SENSITIVE</a></code></strong>. Typically these should be paired with the matching opslimit values.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sodium-crypto-pwhash-str-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="simpara">
   Returns the hashed password.
  </p>
  <p class="simpara">
   In order to produce the same password hash from the same password, the same values for <code class="parameter">opslimit</code> and <code class="parameter">memlimit</code> must be used. These are embedded within the generated hash, so
   everything that&#039;s needed to verify the hash is included. This allows
   the <span class="function"><a href="function.sodium-crypto-pwhash-str-verify.php" class="function">sodium_crypto_pwhash_str_verify()</a></span> function to verify the hash without
   needing separate storage for the other parameters.
  </p>
 </div>


  <div class="refsect1 examples" id="refsect1-function.sodium-crypto-pwhash-str-examples">
  <h3 class="title">Esempi</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>sodium_crypto_pwhash_str()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$password </span><span style="color: #007700">= </span><span style="color: #DD0000">'password'</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">sodium_crypto_pwhash_str</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$password</span><span style="color: #007700">,<br />    </span><span style="color: #0000BB">SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE</span><span style="color: #007700">,<br />    </span><span style="color: #0000BB">SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE<br /></span><span style="color: #007700">);</span></span></code></div>
   </div>

   <div class="example-contents"><p>Il precedente esempio visualizzerà
qualcosa simile a:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">$argon2id$v=19$m=65536,t=2,p=1$oWIfdaXwWwhVmovOBc2NAQ$EbsZ+JnZyyavkafS0hoc4HdaOB0ILWZESAZ7kVGa+Iw</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.sodium-crypto-pwhash-str-notes">
  <h3 class="title">Note</h3>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <span class="simpara">
    Hashes are calculated using the Argon2ID algorithm,
    providing resistance to both GPU and side-channel attacks.
    In contrast to the <span class="function"><a href="function.password-hash.php" class="function">password_hash()</a></span> function,
    there is no salt parameter (a salt is generated automatically),
    and the <code class="parameter">opslimit</code> and
    <code class="parameter">memlimit</code> parameters are not optional.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sodium-crypto-pwhash-str-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.sodium-crypto-pwhash-str-verify.php" class="function" rel="rdfs-seeAlso">sodium_crypto_pwhash_str_verify()</a> - Verifies that a password matches a hash</span></li>
   <li><span class="function"><a href="function.sodium-crypto-pwhash.php" class="function" rel="rdfs-seeAlso">sodium_crypto_pwhash()</a> - Derive a key from a password, using Argon2</span></li>
   <li><span class="function"><a href="function.password-hash.php" class="function" rel="rdfs-seeAlso">password_hash()</a> - Creates a password hash</span></li>
   <li><span class="function"><a href="function.password-verify.php" class="function" rel="rdfs-seeAlso">password_verify()</a> - Verifies that a password matches a hash</span></li>
   <li><a href="https://download.libsodium.org/doc/password_hashing/the_argon2i_function.html" class="link external">&raquo;&nbsp;Libsodium Argon2 docs</a></li>
  </ul>
 </div>



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