【问题标题】:auth attempt is not working but data will store in users身份验证尝试不起作用,但数据将存储在用户中
【发布时间】:2019-10-15 09:01:55
【问题描述】:

我的 auth:: 尝试不起作用。 但是我的注册表单数据将存储在用户数据库中,并且我还应用了 auth::check(),它也不起作用。

这是控制器

public function showLoginform(Request $request){

    $this->validate($request,[
        'email' => 'required',
        'password' => 'required',
    ]);

     $user_data = array(
         'email' => $request->get('email'),
         'password' => $request->get('password')
     );


 if(Auth::attempt($user_data)){
        //return \redirect::to("logged in successfuly");
        echo "yes match";
    } else{
        echo "not match";
       // return "oopps something wrong";
    } 

}

这是我的模型

类用户扩展可验证 { 使用通知;

protected $table="users";


protected $fillable = [ 'name', 'email', 'password', 'phonenumber' , 'profession' , 'images' ];


protected $hidden = [
    'password', 'remember_token',
];
}

【问题讨论】:

  • 您是否对密码进行了哈希处理?您应该散列密码以使用 Auth::attempt

标签: php laravel authentication


【解决方案1】:

使用 $request->input 代替 $request->get

public function showLoginform(Request $request){

    $this->validate($request,[
        'email' => 'required',
        'password' => 'required',
    ]);

     $user_data = array(
         'email' => $request->input('email'),
         'password' => $request->input('password')
     );


 if(Auth::attempt($user_data)){
        //return \redirect::to("logged in successfuly");
        echo "yes match";
    } else{
        echo "not match";
       // return "oopps something wrong";
    } 

}

【讨论】:

    猜你喜欢
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 2015-07-13
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多