亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

LoginController 未對用戶進行身份驗證

LoginController 未對用戶進行身份驗證

PHP
青春有我 2021-11-26 14:49:24
我首先創建了一個注冊和登錄,一切都很順利,一旦我完成了我的注冊,登錄將無法驗證它總是說無效數據,相信我有一些有效數據它只是不起作用我嘗試將憑據從“密碼”更改為“密碼”(用戶名相同),但仍然沒有任何效果LoginController,同樣在你問我之前,我確實將它們與 web.php 鏈接到登錄表單,并且我確實為令牌添加了 @csrf,所以一切都應該順利進行namespace App\Http\Controllers;use Illuminate\Http\Request;use Illuminate\Support\Facades\Auth;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Input;use App\User;class LoginController extends Controller {    /**     * Handle an authentication attempt.     *     * @param  \Illuminate\Http\Request $request     *     * @return Response     */    public function authenticate(Request $request){        $username = $request->input('username');        $password = $request->input('password');        $credentials = ['username' => $username, 'password' => $password];        if (Auth::check()) {            return redirect('/register');        } else {            if (Auth::attempt($credentials)) {                // Authentication passed...                $request->session()->flash('loginsuccess', 'loginsuccess');                return redirect('/');            } else {                $request->session()->flash('loginfailed', 'loginfailed');                return redirect('/');            }        }    }}我希望用戶在登錄后進行身份驗證。(PS 我是 Laravel 的新手)
查看完整描述

3 回答

?
慕尼黑5688855

TA貢獻1848條經驗 獲得超2個贊

這是自定義身份驗證嗎?如果是這樣,我懷疑您將散列密碼存儲在寄存器中,但未在登錄時對其進行散列,這意味著密碼不匹配。

php artisan make:auth如果您還沒有使用 Laravel,我建議您使用它。


查看完整回答
反對 回復 2021-11-26
?
繁星點點滴滴

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這將為您構建登錄和注冊邏輯。


查看完整回答
反對 回復 2021-11-26
?
慕哥9229398

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']),

]);

我將從這兩個項目開始。如果問題仍然存在,您可能還希望在問題中包含錯誤消息以幫助追蹤問題。


查看完整回答
反對 回復 2021-11-26
  • 3 回答
  • 0 關注
  • 227 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號