如何将密码从md5转换为laravel加密方法

编程入门 行业动态 更新时间:2024-10-26 18:16:34
本文介绍了如何将密码从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?

推荐答案

有没有直接的方法可以做到这一点?

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加密方法

本文发布于:2023-10-24 23:59:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525365.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   如何将   密码   方法   laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!