本文介绍了如何将密码从md5转换为laravel加密方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将现有项目重新开发为laravel.
I want to re-develop my existing project to laravel.
在旧系统中,我将密码存储到md5中.
In my old system I store password into md5.
现在如何根据现有用户的laravel哈希方法将其转换.
Now how can I convert it according to laravel hash method for existing user.
有没有直接的方法可以做到这一点?
Is there any direct method to do it?
推荐答案
没有直接方法,但是您可以通过覆盖Auth/AuthController.php
中的postLogin
来实现,因此它将检查密码是否为md5
格式,然后使用laravel哈希方法对其进行加密,否则用户将正常连接,就像:
No there's no direct method, but you could achieve that by overriding postLogin
inside Auth/AuthController.php
so it will check if the password is in md5
format then recrypt it with laravel hashing method else the user will connect normally, like :
public function postLogin(Request $request)
{
$this->validate($request, [
'login' => 'required', 'password' => 'required',
]);
$credentials = $this->getCredentials($request);
//Get the user
$user = User::where('login', $request->login)->first();
//If Hached by bcrypt
if (Auth::attempt($credentials, $request->has('remember')))
{
return redirect()->intended($this->redirectPath());
}
else //Else if Hached by md5
{
if( $user && $user->password == md5($request->password) )
{
$user->password = Hash::make($request->password);
$user->save();
if($user->authorized){
$user->save();
Auth::login($user);
}else
Auth::logout();
}
}
return redirect($this->loginPath())
->withInput($request->only('login', 'remember'))
->withErrors([
'login' => $this->getFailedLoginMessage(),
]);
}
希望这会有所帮助.
这篇关于如何将密码从md5转换为laravel加密方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!