|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<refentry xml:id="function.openssl-password-hash" xmlns="http://docbook.org/ns/docbook"> |
| 3 | + <refnamediv> |
| 4 | + <refname>openssl_password_hash</refname> |
| 5 | + <refpurpose>Create a password hash using OpenSSL's Argon2 implementation</refpurpose> |
| 6 | + </refnamediv> |
| 7 | + |
| 8 | + <refsect1 role="description"> |
| 9 | + &reftitle.description; |
| 10 | + <methodsynopsis> |
| 11 | + <type>string</type><methodname>openssl_password_hash</methodname> |
| 12 | + <methodparam><type>string</type><parameter>algo</parameter></methodparam> |
| 13 | + <methodparam><type>string</type><parameter>password</parameter></methodparam> |
| 14 | + <methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>[]</initializer></methodparam> |
| 15 | + </methodsynopsis> |
| 16 | + <para> |
| 17 | + Creates a password hash using OpenSSL's Argon2 implementation. This is an |
| 18 | + alternative to <function>password_hash</function> that uses OpenSSL as |
| 19 | + the backend, which may offer hardware acceleration on some platforms. |
| 20 | + </para> |
| 21 | + <para> |
| 22 | + This function is only available when PHP is compiled with OpenSSL |
| 23 | + support that includes Argon2 (<literal>HAVE_OPENSSL_ARGON2</literal>). |
| 24 | + </para> |
| 25 | + </refsect1> |
| 26 | + |
| 27 | + <refsect1 role="parameters"> |
| 28 | + &reftitle.parameters; |
| 29 | + <para> |
| 30 | + <variablelist> |
| 31 | + <varlistentry> |
| 32 | + <term><parameter>algo</parameter></term> |
| 33 | + <listitem> |
| 34 | + <para> |
| 35 | + The password hashing algorithm. Supported values: |
| 36 | + <literal>"argon2id"</literal> and <literal>"argon2i"</literal>. |
| 37 | + </para> |
| 38 | + </listitem> |
| 39 | + </varlistentry> |
| 40 | + <varlistentry> |
| 41 | + <term><parameter>password</parameter></term> |
| 42 | + <listitem> |
| 43 | + <para> |
| 44 | + The user's password. |
| 45 | + </para> |
| 46 | + </listitem> |
| 47 | + </varlistentry> |
| 48 | + <varlistentry> |
| 49 | + <term><parameter>options</parameter></term> |
| 50 | + <listitem> |
| 51 | + <para> |
| 52 | + An associative &array; of options. Supported keys: |
| 53 | + <simplelist> |
| 54 | + <member> |
| 55 | + <literal>memory_cost</literal> - Maximum memory (in KiB) that may |
| 56 | + be used to compute the hash |
| 57 | + </member> |
| 58 | + <member> |
| 59 | + <literal>time_cost</literal> - Maximum amount of time it may take |
| 60 | + to compute the hash |
| 61 | + </member> |
| 62 | + <member> |
| 63 | + <literal>threads</literal> - Number of threads to use for |
| 64 | + computing the hash |
| 65 | + </member> |
| 66 | + </simplelist> |
| 67 | + </para> |
| 68 | + </listitem> |
| 69 | + </varlistentry> |
| 70 | + </variablelist> |
| 71 | + </para> |
| 72 | + </refsect1> |
| 73 | + |
| 74 | + <refsect1 role="returnvalues"> |
| 75 | + &reftitle.returnvalues; |
| 76 | + <para> |
| 77 | + Returns the password hash as a &string;. |
| 78 | + </para> |
| 79 | + </refsect1> |
| 80 | + |
| 81 | + <refsect1 role="errors"> |
| 82 | + &reftitle.errors; |
| 83 | + <para> |
| 84 | + Throws a <classname>ValueError</classname> if <parameter>algo</parameter> |
| 85 | + is not one of the supported values |
| 86 | + (<literal>"argon2i"</literal> or <literal>"argon2id"</literal>). |
| 87 | + </para> |
| 88 | + <para> |
| 89 | + Throws an <classname>Error</classname> if the hashing operation fails |
| 90 | + for an unknown reason. |
| 91 | + </para> |
| 92 | + </refsect1> |
| 93 | + |
| 94 | + <refsect1 role="changelog"> |
| 95 | + &reftitle.changelog; |
| 96 | + <informaltable> |
| 97 | + <tgroup cols="2"> |
| 98 | + <thead> |
| 99 | + <row> |
| 100 | + <entry>&Version;</entry> |
| 101 | + <entry>&Description;</entry> |
| 102 | + </row> |
| 103 | + </thead> |
| 104 | + <tbody> |
| 105 | + <row> |
| 106 | + <entry>8.4.0</entry> |
| 107 | + <entry> |
| 108 | + Function added. |
| 109 | + </entry> |
| 110 | + </row> |
| 111 | + </tbody> |
| 112 | + </tgroup> |
| 113 | + </informaltable> |
| 114 | + </refsect1> |
| 115 | + |
| 116 | + <refsect1 role="examples"> |
| 117 | + &reftitle.examples; |
| 118 | + <example> |
| 119 | + <title><function>openssl_password_hash</function> example</title> |
| 120 | + <programlisting role="php"> |
| 121 | +<![CDATA[ |
| 122 | +<?php |
| 123 | +$hash = openssl_password_hash('argon2id', 'my-secret-password'); |
| 124 | +echo $hash; |
| 125 | +?> |
| 126 | +]]> |
| 127 | + </programlisting> |
| 128 | + &example.outputs.similar; |
| 129 | + <screen> |
| 130 | +<![CDATA[ |
| 131 | +$argon2id$v=19$m=65536,t=4,p=1$c29tZXNhbHR2YWx1ZQ$hashvalue... |
| 132 | +]]> |
| 133 | + </screen> |
| 134 | + </example> |
| 135 | + <example> |
| 136 | + <title><function>openssl_password_hash</function> with custom options</title> |
| 137 | + <programlisting role="php"> |
| 138 | +<![CDATA[ |
| 139 | +<?php |
| 140 | +$hash = openssl_password_hash('argon2id', 'my-secret-password', [ |
| 141 | + 'memory_cost' => 65536, |
| 142 | + 'time_cost' => 4, |
| 143 | + 'threads' => 1, |
| 144 | +]); |
| 145 | +?> |
| 146 | +]]> |
| 147 | + </programlisting> |
| 148 | + </example> |
| 149 | + </refsect1> |
| 150 | + |
| 151 | + <refsect1 role="seealso"> |
| 152 | + &reftitle.seealso; |
| 153 | + <para> |
| 154 | + <simplelist> |
| 155 | + <member><function>openssl_password_verify</function></member> |
| 156 | + <member><function>password_hash</function></member> |
| 157 | + </simplelist> |
| 158 | + </para> |
| 159 | + </refsect1> |
| 160 | + |
| 161 | +</refentry> |
| 162 | +<!-- Keep this comment at the end of the file |
| 163 | +Local variables: |
| 164 | +mode: sgml |
| 165 | +sgml-omittag:t |
| 166 | +sgml-shorttag:t |
| 167 | +sgml-minimize-attributes:nil |
| 168 | +sgml-always-quote-attributes:t |
| 169 | +sgml-indent-step:1 |
| 170 | +sgml-indent-data:t |
| 171 | +indent-tabs-mode:nil |
| 172 | +sgml-parent-document:nil |
| 173 | +sgml-default-dtd-file:"~/.phpdoc/manual.ced" |
| 174 | +sgml-exposed-tags:nil |
| 175 | +sgml-local-catalogs:nil |
| 176 | +sgml-local-ecat-files:nil |
| 177 | +End: |
| 178 | +vim600: syn=xml fen fdm=syntax fdl=2 si |
| 179 | +vim: et tw=78 syn=sgml |
| 180 | +vi: ts=1 sw=1 |
| 181 | +--> |
0 commit comments