繁体   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