laravel 4 custom named password column

前端 未结 4 2055
情书的邮戳
情书的邮戳 2020-11-29 10:49

So I found a few problems already which says that you have to override getAuthPassword() to give custom name of password column from database. Tried putting this method with

4条回答
  •  春和景丽
    2020-11-29 11:23

    tldr; You can name your password field anything you like, as long as your User model implements the interface correctly.

    However you can't pass different array key to the Auth::attempt method - only password index can be there

    First off you're doing it wrong - you need to pass an array of credentials as 1st param:

    if (Auth::attempt(Input::only('user_displayName', 'user_password')))
    

    Next, unfortunately Eloquent provider has hard-coded password array index in the code, so you can't pass user_password to the attempt method.

    So this is what you need:

    $credentials = Input::only('user_displayName');
    $credentials['password'] = Input::get('user_password');
    
    if (Auth::attempt($credentials))
    
    // or simply rename the input in your form to password and:
    if (Auth::attempt(Input::only('user_displayName', 'password')))
    

提交回复
热议问题