uTools-Manuals/docs/php/sodium_crypto_pwhash_str.html
2019-04-28 19:00:34 +08:00

137 lines
7.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>Get an ASCII-encoded hash</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><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)</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">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>sodium_crypto_pwhash_str</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$opslimit</code></span>
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$memlimit</code></span>
) : <span class="type">string</span></div>
<p class="para rdfs-comment">
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">参数</h3>
<dl>
<dt>
<code class="parameter">password</code></dt>
<dd>
<p class="para">
<span class="type"><a href="language.types.string.html" class="type string">string</a></span>; The password to generate a hash for.
</p>
</dd>
<dt>
<code class="parameter">opslimit</code></dt>
<dd>
<p class="para">
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>SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE</code></strong>, <strong><code>SODIUM_CRYPTO_PWHASH_OPSLIMIT_MODERATE</code></strong> and <strong><code>SODIUM_CRYPTO_PWHASH_OPSLIMIT_SENSITIVE</code></strong>.
</p>
</dd>
<dt>
<code class="parameter">memlimit</code></dt>
<dd>
<p class="para">
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>SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE</code></strong>, <strong><code>SODIUM_CRYPTO_PWHASH_MEMLIMIT_MODERATE</code></strong>, and <strong><code>SODIUM_CRYPTO_PWHASH_MEMLIMIT_SENSITIVE</code></strong>. Typically these should be paired with the matching opslimit values.
</p>
</dd>
</dl>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.sodium-crypto-pwhash-str-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns the hashed password, 或者在失败时返回 <strong><code>FALSE</code></strong>.
</p>
<p class="para">
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="sodium_crypto_pwhash_str_verify.html" 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 notes" id="refsect1-function.sodium-crypto-pwhash-str-notes">
<h3 class="title">注释</h3>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
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="password_hash.html" 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.
</p>
</p></blockquote>
</div>
<div class="refsect1 examples" id="refsect1-function.sodium-crypto-pwhash-str-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="openssl_spki_new.example.basic">
<p><strong>Example #1 <span class="function"><a href="password_hash.html" class="function">password_hash()</a></span> example</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'password'</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">sodium_crypto_pwhash_str</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE<br /></span><span style="color: #007700">);</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
$argon2id$v=19$m=65536,t=2,p=1$oWIfdaXwWwhVmovOBc2NAQ$EbsZ+JnZyyavkafS0hoc4HdaOB0ILWZESAZ7kVGa+Iw
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 seealso" id="refsect1-function.sodium-crypto-pwhash-str-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="sodium_crypto_pwhash_str_verify.html" class="function" rel="rdfs-seeAlso">sodium_crypto_pwhash_str_verify()</a> - Verifies that a password matches a hash</span></li>
<li class="member"><span class="function"><a href="sodium_crypto_pwhash.html" class="function" rel="rdfs-seeAlso">sodium_crypto_pwhash()</a> - Derive a key from a password</span></li>
<li class="member"><span class="function"><a href="password_hash.html" class="function" rel="rdfs-seeAlso">password_hash()</a> - 创建密码的散列hash</span></li>
<li class="member"><span class="function"><a href="password_verify.html" class="function" rel="rdfs-seeAlso">password_verify()</a> - 验证密码是否和散列值匹配</span></li>
<li class="member"><a href="https://download.libsodium.org/doc/password_hashing/the_argon2i_function.html" class="link external">&raquo;&nbsp;Libsodium Argon2 docs</a></li>
</ul>
</p>
</div>
</div></div></div></body></html>