Readouble

Laravel master ハッシュ

イントロダクションIntroduction

LaravelのHashファサードは保存するユーザパスワードに対し、安全なBcryptハッシュを提供します。Laravelアプリケーションに組み込まれている、LoginControllerRegisterControllerを使用していれば、登録と認証で自動的にBcrypt使用します。The Laravel Hash facade[/docs/{{version}}/facades] provides secure Bcrypt hashing for storing user passwords. If you are using the built-in LoginController and RegisterController classes that are included with your Laravel application, they will automatically use Bcrypt for registration and authentication.

lightbulb">Tip!! Bcryptは「ストレッチ回数」が調整できるのでパスワードのハッシュには良い選択肢です。つまりハードウェアのパワーを上げればハッシュの生成時間を早くすることができます。{tip} Bcrypt is a great choice for hashing passwords because its "work factor" is adjustable, which means that the time it takes to generate a hash can be increased as hardware power increases.

基本的な使用法Basic Usage

Hashファサードのmakeメソッドを呼び出し、パスワードをハッシュできます。You may hash a password by calling the make method on the Hash facade:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\Controller;

class UpdatePasswordController extends Controller
{
    /**
     * ユーザーパスワードを更新
     *
     * @param  Request  $request
     * @return Response
     */
    public function update(Request $request)
    {
        // 新しいパスワードの長さのバリデーション…

        $request->user()->fill([
            'password' => Hash::make($request->newPassword)
        ])->save();
    }
}

パスワードとハッシュ値の比較Verifying A Password Against A Hash

checkメソッドにより指定した平文文字列と指定されたハッシュ値を比較確認できます。しかしLaravelに含まれているLoginControllerを使っている場合は、これを直接使用することはないでしょう。このコントローラーがこのメソッドを自動的に呼び出します。The check method allows you to verify that a given plain-text string corresponds to a given hash. However, if you are using the LoginController included with Laravel[/docs/{{version}}/authentication], you will probably not need to use this directly, as this controller automatically calls this method:

if (Hash::check('plain-text', $hashedPassword)) {
    // パスワード一致
}

パスワードの再ハッシュが必要か確認Checking If A Password Needs To Be Rehashed

パスワードがハシュされてからハッシャーのストレッチ回数が変更されているかを調べるには、needsRehashメソッドを使います。The needsRehash function allows you to determine if the work factor used by the hasher has changed since the password was hashed:

if (Hash::needsRehash($hashed)) {
    $hashed = Hash::make('plain-text');
}

章選択

開発環境
ビューとテンプレート
公式パッケージ

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

Pagination和文
ペジネーション
ペギネーション
ページネーション
ページ付け
Scaffold和文
スカフォールド
スキャフォールド
型枠生成
本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作