質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

Webサイト

一つのドメイン上に存在するWebページの集合体をWebサイトと呼びます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

ログイン

ログインは、ユーザーがコンピューターシステムにアクセスするプロセスの事を呼びます。

Q&A

解決済

1回答

7518閲覧

Laravel6,adminユーザーのログインでThese credentials do not match our records.がでる

tenlife

総合スコア70

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

Webサイト

一つのドメイン上に存在するWebページの集合体をWebサイトと呼びます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

ログイン

ログインは、ユーザーがコンピューターシステムにアクセスするプロセスの事を呼びます。

1グッド

1クリップ

投稿2020/03/12 22:32

編集2020/03/12 22:40

adminでログインしようとするとThese credentials do not match our recordsが出てログイン出来ません。

下記のサイトを参考にしながらユーザーのマルチ認証をしています。
https://qiita.com/namizatop/items/5d56d96d4c255a0e3a87?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items#auth

userの方はログインも新規登録もうまくいくのですが、
adminは新規登録するとログイン画面に飛ばされます(データベースには登録されている)。
ログインしようとするとThese credentials do not match our recordsが出てきます。

検索したサイト
https://reffect.co.jp/laravel/laravel-authentification-by-code-base
https://stackoverflow.com/questions/48268978/laravel-auth-these-credentials-do-not-match-our-records

register

1<?php 2 3namespace App\Http\Controllers\Admin\Auth; 4 5use App\Http\Controllers\Controller; 6use App\Providers\RouteServiceProvider; 7use App\Models\Admin; 8use Illuminate\Foundation\Auth\RegistersUsers; 9use Illuminate\Support\Facades\Hash; 10use Illuminate\Support\Facades\Validator; 11use Illuminate\Http\Request; 12use Illuminate\Auth\Events\Registered; 13use Illuminate\Support\Facades\Auth; 14 15class RegisterController extends Controller 16{ 17 /* 18 |-------------------------------------------------------------------------- 19 | Register Controller 20 |-------------------------------------------------------------------------- 21 | 22 | This controller handles the registration of new users as well as their 23 | validation and creation. By default this controller uses a trait to 24 | provide this functionality without requiring any additional code. 25 | 26 */ 27 28 use RegistersUsers; 29 30 /** 31 * Where to redirect users after registration. 32 * 33 * @var string 34 */ 35 protected $redirectTo = RouteServiceProvider::ADMIN_HOME; 36 37 /** 38 * Create a new controller instance. 39 * 40 * @return void 41 */ 42 public function __construct() 43 { 44 $this->middleware('guest:admin'); 45 } 46 47 // Guardの認証方法を指定 48 protected function guard() 49 { 50 return Auth::guard('admin'); 51 } 52 53 // 新規登録画面 54 public function showRegistrationForm() 55 { 56 return view('admin.auth.register'); 57 } 58 59 /** 60 * Get a validator for an incoming registration request. 61 * 62 * @param array $data 63 * @return \Illuminate\Contracts\Validation\Validator 64 */ 65 // バリデーション 66 protected function validator(array $data) 67 { 68 return Validator::make($data, [ 69 'name' => ['required', 'string', 'max:255'], 70 'email' => ['required', 'string', 'email', 'max:255', 'unique:admins'], 71 'password' => ['required', 'string', 'min:8', 'confirmed'], 72 ]); 73 } 74 75 /** 76 * Create a new user instance after a valid registration. 77 * 78 * @param array $data 79 * @return \App\Models\Admin 80 */ 81 // 登録処理 82 protected function create(array $data) 83 { 84 return Admin::create([ 85 'name' => $data['name'], 86 'email' => $data['email'], 87 'password' => Hash::make($data['password']), 88 ]); 89 } 90} 91

login

auth

1<?php 2 3return [ 4 5 /* 6 |-------------------------------------------------------------------------- 7 | Authentication Defaults 8 |-------------------------------------------------------------------------- 9 | 10 | This option controls the default authentication "guard" and password 11 | reset options for your application. You may change these defaults 12 | as required, but they're a perfect start for most applications. 13 | 14 */ 15 16 'defaults' => [ 17 'guard' => 'user', 18 'passwords' => 'users', 19 ], 20 21 /* 22 |-------------------------------------------------------------------------- 23 | Authentication Guards 24 |-------------------------------------------------------------------------- 25 | 26 | Next, you may define every authentication guard for your application. 27 | Of course, a great default configuration has been defined for you 28 | here which uses session storage and the Eloquent user provider. 29 | 30 | All authentication drivers have a user provider. This defines how the 31 | users are actually retrieved out of your database or other storage 32 | mechanisms used by this application to persist your user's data. 33 | 34 | Supported: "session", "token" 35 | 36 */ 37 38 'guards' => [ 39 'user' => [ 40 'driver' => 'session', 41 'provider' => 'users', 42 ], 43 44 // Admin用の認証を追加 45 'admin' => [ 46 'driver' => 'session', 47 'provider' => 'admins', 48 ], 49 50 'api' => [ 51 'driver' => 'token', 52 'provider' => 'users', 53 'hash' => false, 54 ], 55 ], 56 57 /* 58 |-------------------------------------------------------------------------- 59 | User Providers 60 |-------------------------------------------------------------------------- 61 | 62 | All authentication drivers have a user provider. This defines how the 63 | users are actually retrieved out of your database or other storage 64 | mechanisms used by this application to persist your user's data. 65 | 66 | If you have multiple user tables or models you may configure multiple 67 | sources which represent each model / table. These sources may then 68 | be assigned to any extra authentication guards you have defined. 69 | 70 | Supported: "database", "eloquent" 71 | 72 */ 73 74 'providers' => [ 75 'users' => [ 76 'driver' => 'eloquent', 77 'model' => App\Models\User::class, 78 ], 79 80 'admins' => [ 81 'driver' => 'eloquent', 82 'model' => App\Models\Admin::class, 83 ], 84 85 // 'users' => [ 86 // 'driver' => 'database', 87 // 'table' => 'users', 88 // ], 89 ], 90 91 /* 92 |-------------------------------------------------------------------------- 93 | Resetting Passwords 94 |-------------------------------------------------------------------------- 95 | 96 | You may specify multiple password reset configurations if you have more 97 | than one user table or model in the application and you want to have 98 | separate password reset settings based on the specific user types. 99 | 100 | The expire time is the number of minutes that the reset token should be 101 | considered valid. This security feature keeps tokens short-lived so 102 | they have less time to be guessed. You may change this as needed. 103 | 104 */ 105 106 'passwords' => [ 107 'users' => [ 108 'provider' => 'users', 109 'table' => 'password_resets', 110 'expire' => 60, 111 'throttle' => 60, 112 ], 113 114 'admins' => [ 115 'provider' => 'admins', 116 'table' => 'password_resets', 117 'expire' => 60, 118 'throttle' => 60, 119 ], 120 ], 121 122 /* 123 |-------------------------------------------------------------------------- 124 | Password Confirmation Timeout 125 |-------------------------------------------------------------------------- 126 | 127 | Here you may define the amount of seconds before a password confirmation 128 | times out and the user is prompted to re-enter their password via the 129 | confirmation screen. By default, the timeout lasts for three hours. 130 | 131 */ 132 133 'password_timeout' => 10800, 134 135]; 136

試したこと
・パスワードの作り方をHash::make('password')とbcryptを使ってやってみるも変化なしでした。
・キャッシュ削除。https://qiita.com/ucan-lab/items/c1e561d20cc591966c25
・ユーザーの作り直し

自分の力では原因を掴めずにいます。

知恵を貸していただきたいです。

よろしくおねがします。

php7.4.2
laravel 6.0

s.k👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

自己解決しました。もっと注意深く確認するべきでした。

// Admin用の認証を追加 'admin' => [ 'driver' => 'session', 'provider' => 'users', これを-> 'provider' => 'admins' ],

投稿2020/03/12 22:42

編集2020/03/16 21:36
tenlife

総合スコア70

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問