3 回答

TA貢獻1848條經驗 獲得超2個贊
這是自定義身份驗證嗎?如果是這樣,我懷疑您將散列密碼存儲在寄存器中,但未在登錄時對其進行散列,這意味著密碼不匹配。
php artisan make:auth
如果您還沒有使用 Laravel,我建議您使用它。

TA貢獻1803條經驗 獲得超3個贊
我要檢查幾件事,在您注冊新用戶后密碼是否被加密?
如果打印憑據會發生什么?
public function authenticate(Request $request){
$username = $request->input('username');
$password = $request->input('password');
dd($password);
dd($username);// remove the first dd after your check to see the username output
此外,這個邏輯對我來說沒有意義:
if (Auth::check()) {
return redirect('/register');
...
如果用戶已經通過您的應用程序的身份驗證,為什么要重定向用戶?您應該將他重定向到主頁,如下所示:
return redirect('/home'); // or ('/') depends on your routes
此外,Laravel 提供了一個簡單的身份驗證腳手架,例如,您可以創建一個新項目laravel new project設置數據庫并運行以下命令,php artisan make:auth這將為您構建登錄和注冊邏輯。

TA貢獻1877條經驗 獲得超6個贊
檢查 config/auth.php 并確保您已設置用戶提供程序:
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
// Make sure these values are correct
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
您是否創建了自定義 RegisterController?如果是這樣,請確保在創建模型時對用戶的密碼進行哈希處理:
$user = User::create([
'username' => $input['username'],
'password'=> Hash::make($input['password']),
]);
我將從這兩個項目開始。如果問題仍然存在,您可能還希望在問題中包含錯誤消息以幫助追蹤問題。
- 3 回答
- 0 關注
- 227 瀏覽
添加回答
舉報