Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions reference/openssl/functions/openssl-password-hash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 29cecd7f180bfdae00ebd6128b6dd4255eb30365 Maintainer: lacatoire Status: ready -->
<refentry xml:id="function.openssl-password-hash" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>openssl_password_hash</refname>
<refpurpose>Crea un hash de contraseña usando la implementación de Argon2 de OpenSSL</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>openssl_password_hash</methodname>
<methodparam><type>string</type><parameter>algo</parameter></methodparam>
<methodparam><type>string</type><parameter>password</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>[]</initializer></methodparam>
</methodsynopsis>
<para>
Crea un hash de contraseña usando la implementación de Argon2 de OpenSSL.
Es una alternativa a <function>password_hash</function> que utiliza OpenSSL
como backend, lo que puede ofrecer aceleración por hardware en algunas
plataformas.
</para>
<para>
Esta función solo está disponible cuando PHP se compila con soporte de
OpenSSL que incluye Argon2 (<literal>HAVE_OPENSSL_ARGON2</literal>).
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>algo</parameter></term>
<listitem>
<para>
El algoritmo de hash de contraseña. Valores soportados:
<literal>"argon2id"</literal> y <literal>"argon2i"</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>password</parameter></term>
<listitem>
<para>
La contraseña del usuario.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>options</parameter></term>
<listitem>
<para>
Un &array; asociativo de opciones. Claves soportadas:
<simplelist>
<member>
<literal>memory_cost</literal> - Memoria máxima (en KiB) que puede
utilizarse para calcular el hash
</member>
<member>
<literal>time_cost</literal> - Tiempo máximo que puede tomar
calcular el hash
</member>
<member>
<literal>threads</literal> - Número de hilos a utilizar para
calcular el hash
</member>
</simplelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Devuelve el hash de la contraseña como una &string;.
</para>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<para>
Lanza un <classname>ValueError</classname> si <parameter>algo</parameter>
no es uno de los valores soportados
(<literal>"argon2i"</literal> o <literal>"argon2id"</literal>).
</para>
<para>
Lanza un <classname>Error</classname> si la operación de hashing falla
por una razón desconocida.
</para>
</refsect1>

<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
Se ha añadido la función.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Ejemplo con <function>openssl_password_hash</function></title>
<programlisting role="php">
<![CDATA[
<?php
$hash = openssl_password_hash('argon2id', 'my-secret-password');
echo $hash;
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
$argon2id$v=19$m=65536,t=4,p=1$c29tZXNhbHR2YWx1ZQ$hashvalue...
]]>
</screen>
</example>
<example>
<title><function>openssl_password_hash</function> con opciones personalizadas</title>
<programlisting role="php">
<![CDATA[
<?php
$hash = openssl_password_hash('argon2id', 'my-secret-password', [
'memory_cost' => 65536,
'time_cost' => 4,
'threads' => 1,
]);
?>
]]>
</programlisting>
</example>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>openssl_password_verify</function></member>
<member><function>password_hash</function></member>
</simplelist>
</para>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
148 changes: 148 additions & 0 deletions reference/openssl/functions/openssl-password-verify.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 29cecd7f180bfdae00ebd6128b6dd4255eb30365 Maintainer: lacatoire Status: ready -->
<refentry xml:id="function.openssl-password-verify" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>openssl_password_verify</refname>
<refpurpose>Verifica una contraseña frente a un hash usando la implementación de Argon2 de OpenSSL</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>openssl_password_verify</methodname>
<methodparam><type>string</type><parameter>algo</parameter></methodparam>
<methodparam><type>string</type><parameter>password</parameter></methodparam>
<methodparam><type>string</type><parameter>hash</parameter></methodparam>
</methodsynopsis>
<para>
Verifica que una contraseña coincida con un hash creado por
<function>openssl_password_hash</function>.
</para>
<para>
Esta función solo está disponible cuando PHP se compila con soporte de
OpenSSL que incluye Argon2 (<literal>HAVE_OPENSSL_ARGON2</literal>).
</para>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>algo</parameter></term>
<listitem>
<para>
El algoritmo de hash de contraseña. Valores soportados:
<literal>"argon2id"</literal> y <literal>"argon2i"</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>password</parameter></term>
<listitem>
<para>
La contraseña del usuario.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>hash</parameter></term>
<listitem>
<para>
Un hash creado por <function>openssl_password_hash</function>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Devuelve &true; si la contraseña y el hash coinciden, &false; en caso contrario.
</para>
</refsect1>

<refsect1 role="errors">
&reftitle.errors;
<para>
Lanza un <classname>ValueError</classname> si <parameter>algo</parameter>
no es uno de los valores soportados
(<literal>"argon2i"</literal> o <literal>"argon2id"</literal>).
</para>
</refsect1>

<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
Se ha añadido la función.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Ejemplo con <function>openssl_password_verify</function></title>
<programlisting role="php">
<![CDATA[
<?php
$hash = openssl_password_hash('argon2id', 'my-secret-password');

if (openssl_password_verify('argon2id', 'my-secret-password', $hash)) {
echo 'Password matches.';
} else {
echo 'Password does not match.';
}
?>
]]>
</programlisting>
</example>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>openssl_password_hash</function></member>
<member><function>password_verify</function></member>
</simplelist>
</para>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->