Files
php-doc-ru/reference/hash/functions/hash-equals.xml
2022-11-08 17:50:17 +03:00

122 lines
3.8 KiB
XML
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.

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 91e303f2d27cbca485137230fa7d2e50e75f19a6 Maintainer: rjhdby Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.hash-equals" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>hash_equals</refname>
<refpurpose>Сравнение строк, нечувствительное к атакам по времени</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>hash_equals</methodname>
<methodparam><type>string</type><parameter>known_string</parameter></methodparam>
<methodparam><type>string</type><parameter>user_string</parameter></methodparam>
</methodsynopsis>
<para>
Сравнивает две строки на идентичность, используя одинаковое время, вне
зависимости, равны они или нет.
</para>
<para>
Эта функция может использоваться для предотвращения атак по времени; к примеру
при проверке хешей паролей с помощью <function>crypt</function>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>known_string</parameter></term>
<listitem>
<para>
Строка известной длины, с которой будет производиться сравнение.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>user_string</parameter></term>
<listitem>
<para>
Проверяемая строка.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Возвращает &true; если строки идентичны и &false; если нет.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example xml:id="foobar.examples.basic">
<title>Пример использования <function>hash_equals</function></title>
<programlisting role="php">
<![CDATA[
<?php
$expected = crypt('12345', '$2a$07$usesomesillystringforsalt$');
$correct = crypt('12345', '$2a$07$usesomesillystringforsalt$');
$incorrect = crypt('apple', '$2a$07$usesomesillystringforsalt$');
var_dump(hash_equals($expected, $correct));
var_dump(hash_equals($expected, $incorrect));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
bool(true)
bool(false)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
Оба аргумента должны быть одной длины.
Если переданы аргументы разной длины, то будет немедленно возвращено
&false;, и длина известной строки может быть определена в случае
атаки по времени.
</para>
</note>
<note>
<para>
Крайне важно задавать строку с пользовательскими данными вторым аргументом, а не первым.
</para>
</note>
</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
-->