自定义身份验证和密码加密 laravel 5

custom authenticate and password encryption laravel 5

目前,我正在做一个 laravel 5 项目。 我想对密码使用我的自定义加密,所以我做了一个函数,我尝试使用它。 首先,我覆盖了 postLogin 函数,并添加了新密码加密。

public function postLogin(Request $request)
{
    $email = $request->get('email');
    $password = $this->hashPassword($request->get('password'));
    $this->validate($request, [
        $this->loginUsername() => 'required', 'password' => 'required',
    ]);

    // If the class is using the ThrottlesLogins trait, we can automatically throttle
    // the login attempts for this application. We'll key this by the username and
    // the IP address of the client making these requests into this application.
    $throttles = $this->isUsingThrottlesLoginsTrait();

    if ($throttles && $this->hasTooManyLoginAttempts($request)) {
        return $this->sendLockoutResponse($request);
    }

    $credentials = ['email' => $email, 'password' => $this->hashPassword($password)];

    if (Auth::attempt(['email' => $email, 'password' => $this->hashPassword($password)])) {
        // Authentication passed...
        return $this->handleUserWasAuthenticated($request, $throttles);
    }

    // If the login attempt was unsuccessful we will increment the number of attempts
    // to login and redirect the user back to the login form. Of course, when this
    // user surpasses their maximum number of attempts they will get locked out.
    if ($throttles) {
        $this->incrementLoginAttempts($request);
    }

    return redirect($this->loginPath())
        ->withInput($request->only($this->loginUsername(), 'remember'))
        ->withErrors([
            $this->loginUsername() => $this->getFailedLoginMessage(),
        ]);
}

正如您在代码中看到的那样,我调用了函数 hashPassword,它起作用了,但问题是 "Auth::attempt" returns 总是 false,尽管我的数据库中有用户,使用正确的数据。
请问有什么解决办法吗?
非常感谢
亲切的问候

尝试保留 'password' 以外的名称 ok 密码字段,例如 'mypass' 或其他.. auth 自动散列您提供的密码密钥的值。

我找到了解决办法!!!
我将 "attempt" 更改为 "login",现在效果很好 :D
谢谢大家

您必须提供纯文本密码:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    /**
     * Handle an authentication attempt.
     *
     * @return Response
     */
    public function authenticate()
    {
        if (Auth::attempt(['email' => $email, 'password' => $password])) {
            // Authentication passed...
            return redirect()->intended('dashboard');
        }
    }
}

官方参考: https://laravel.com/docs/5.6/authentication#included-authenticating