簡體   English   中英

Laravel 5.5在登錄時更改密碼加密

[英]Laravel 5.5 change password encryption on login

我想更改Laravel的默認密碼。 我想用我自己的。 對於注冊,我知道我該怎么做:在RegisterController中,我可以更改bcrypt函數

/**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        return User::create([
            'username' => $data['username'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }

但是,在哪里可以更改登錄名檢查密碼是否有效的方式?

在這種情況下,您需要使用自己的邏輯來檢查密碼,然后使用loginUsingId()方法:

if (yourMethodForPasswordCheck($request->password, $user->password)) {
    auth()->loginUsingId($user->id);
}

或者,您可以使用login()方法並傳遞User實例:

if (yourMethodForPasswordCheck($request->password, $user->password)) {
    auth()->login($user);
}

https://laravel.com/docs/5.5/authentication#other-authentication-methods

Hash::check

if (Hash::check('secret', $hashedPassword))
{
    // The passwords match...
}

要么

$userdata = array(
    'email'     => Input::get('email'),
    'password'  => Input::get('password')
);

// attempt to do the login
if (Auth::attempt($userdata)) {
   // success
}

可以使用登錄

use Illuminate\Support\Facades\Auth;

Auth::login($user); or
Auth::loginUsingId(1, true); # true is remeber me option

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM