Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

follow php/doc-en#4455 #268

Merged
merged 3 commits into from
Mar 9, 2025
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
34 changes: 20 additions & 14 deletions reference/password/functions/password-hash.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 5bc68add3da3cd18c40f851e944b15095d3a26aa Maintainer: takagi Status: ready -->
<!-- EN-Revision: e302f07943465892db7f72469e2ce9b42c4f763f Maintainer: takagi Status: ready -->
<!-- Credits: mumumu -->
<refentry xml:id="function.password-hash" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
Expand Down Expand Up @@ -39,9 +39,9 @@
</listitem>
<listitem>
<simpara>
<constant>PASSWORD_BCRYPT</constant> - <constant>CRYPT_BLOWFISH</constant>
アルゴリズムを使ってハッシュを作ります。これは標準の <function>crypt</function>
互換のハッシュで、識別子 "$2y$" を使った場合の結果を作ります。
<constant>PASSWORD_BCRYPT</constant> - bcrypt アルゴリズムを使ってハッシュを作ります。
これは標準の <function>crypt</function>
互換のハッシュで、識別子 <literal>$2y$</literal> を使った場合の結果を作ります。
その結果は、常に 60 文字の文字列になります。&return.falseforfailure;。
</simpara>
</listitem>
Expand Down Expand Up @@ -90,8 +90,8 @@
</para>

<para>
省略した場合のデフォルトは <literal>10</literal> です。この値でもかまいませんが、
ハードウェアの性能が許すならもう少し高くすることもできます
省略した場合のデフォルトは <literal>12</literal> です。この値でもかまいませんが、
ハードウェアの性能に応じて調整することもできます
</para>
</listitem>
</itemizedlist>
Expand Down Expand Up @@ -199,6 +199,13 @@
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
<constant>PASSWORD_BCRYPT</constant> アルゴリズムのデフォルトの <literal>cost</literal> オプションの値が
<literal>10</literal> から <literal>12</literal> に引き上げられました。
</entry>
</row>
<row>
<entry>8.0.0</entry>
<entry>
Expand Down Expand Up @@ -272,7 +279,7 @@ echo password_hash("rasmuslerdorf", PASSWORD_DEFAULT);
&example.outputs.similar;
<screen>
<![CDATA[
$2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a
$2y$12$4Umg0rCJwMswRw/l.SwHvuQV01coP0eWmGzd61QH2RvAOMANUBGC.
]]>
</screen>
</example>
Expand All @@ -284,11 +291,10 @@ $2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a
<![CDATA[
<?php
/**
* この例では、BCRYPT のコストをデフォルトより上げて、12 にします。
* また、アルゴリズムを BCRYPT に変えたことにも注目しましょう。結果は常に 60 文字になります。
* この例では、bcrypt のコストを上げて、13 にします。
*/
$options = [
'cost' => 12,
'cost' => 13,
];
echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options);
?>
Expand All @@ -297,7 +303,7 @@ echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options);
&example.outputs.similar;
<screen>
<![CDATA[
$2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
$2y$13$xeDfQumlmdm0Sco.4qmH1OGfUUmOcuRmfae0dPJhjX1Bq0yYhqbNi
]]>
</screen>
</example>
Expand All @@ -311,13 +317,13 @@ $2y$12$QjSH496pcT5CEbzjD/vtVeH03tfHKFy36d4J0Ltp3lRtee9HDxY3K
/**
* このコードは、サーバーをベンチマークして、どの程度のコストに耐えられるかを判断します。
* サーバーに負荷をかけすぎない範囲で、できるだけ高めのコストを設定したいものです。
* 基準として 10 程度からはじめ、サーバーが十分に高速なら、できるだけ上げていきましょう。
* 基準として 11 程度からはじめ、サーバーが十分に高速なら、できるだけ上げていきましょう。
* 以下のコードでは、ストレッチングの時間を 350 ミリ秒以内にすることを狙っています。
* 対話形式のログインを扱う際の許容時間としては、このあたりが適切でしょう。
*/
$timeTarget = 0.350; // 350 ミリ秒

$cost = 10;
$cost = 11;
do {
$cost++;
$start = microtime(true);
Expand All @@ -332,7 +338,7 @@ echo "Appropriate Cost Found: " . $cost;
&example.outputs.similar;
<screen>
<![CDATA[
Appropriate Cost Found: 12
Appropriate Cost Found: 13
]]>
</screen>
</example>
Expand Down
6 changes: 3 additions & 3 deletions reference/password/functions/password-needs-rehash.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: ff492e168a557e4dd17574023b7c3cb21b14df3b Maintainer: takagi Status: ready -->
<!-- EN-Revision: e302f07943465892db7f72469e2ce9b42c4f763f Maintainer: takagi Status: ready -->
<!-- Credits: mumumu -->

<refentry xml:id="function.password-needs-rehash" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
Expand Down Expand Up @@ -97,11 +97,11 @@
<?php

$password = 'rasmuslerdorf';
$hash = '$2y$10$YCFsG6elYca568hBi2pZ0.3LDL5wjgxct1N8w/oLR/jfHsiQwCqTS';
$hash = '$2y$12$4Umg0rCJwMswRw/l.SwHvuQV01coP0eWmGzd61QH2RvAOMANUBGC.';

$algorithm = PASSWORD_BCRYPT;
// bcrypt の cost パラメータは、ハードウェアの性能の向上にあわせて変えることができます
$options = ['cost' => 12];
$options = ['cost' => 13];

// 格納されたハッシュを、平文のパスワードに対して検証します
if (password_verify($password, $hash)) {
Expand Down
4 changes: 2 additions & 2 deletions reference/password/functions/password-verify.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 5bc68add3da3cd18c40f851e944b15095d3a26aa Maintainer: takagi Status: ready -->
<!-- EN-Revision: e302f07943465892db7f72469e2ce9b42c4f763f Maintainer: takagi Status: ready -->
<refentry xml:id="function.password-verify" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>password_verify</refname>
Expand Down Expand Up @@ -74,7 +74,7 @@
<![CDATA[
<?php
// これをどうやって作ったのかは、password_hash() の例を参照ください
$hash = '$2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a';
$hash = '$2y$12$4Umg0rCJwMswRw/l.SwHvuQV01coP0eWmGzd61QH2RvAOMANUBGC.';

if (password_verify('rasmuslerdorf', $hash)) {
echo 'Password is valid!';
Expand Down