我想将现有项目重新开发为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?
推荐答案
有没有直接的方法可以做到这一点?
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加密方法
发布评论