首页 > 解决方案 > 如何解密密码以登录laravel?

问题描述

更改密码时,我正在使用此功能

public function passwordChange(Request $request, $userId)
    {
        $user = User::find($userId);
        $user->password = Crypt::encrypt(Input::get('password'));
        $user->save();
        return redirect('my-profile');
    }

所以在我的mongoDb数据库中以加密形式插入密码,所以每当我当时必须登录系统时,如何将我的密码与数据库密码进行比较

 public function authenticate(Request $request)
    {

        $rules = array(
            'company_email' => 'required|email|exists:users,company_email',
            'password' => 'required|string|max:20|min:4',
        );

        $validator = Validator::make(Input::all(), $rules);
        if ($validator->fails()) 
        {
            return view('pages.login')->with('v_errors', $validator->errors()->messages());
        } 
        else 
        {
            //get email and query
            $authenticateMe = $request->only('company_email', 'password');
            $user = User::where($authenticateMe)->first();

            if (empty($user)) 
            {
                return view('pages.login')->with('not_exists', 'true');
            }
            //session set
            // Session::put('key', $user->username, $user->file);
            Session::put('key', ['username' => $user->username, 'email' => $user->company_email, 'userId' => $user->id, 'profilePicture' => $user->file]);
            return redirect('my-profile');
        }
    }

我没有使用 php artisan make:auth 有人可以帮忙吗?

标签: phplaravelmongodbeloquent

解决方案


不要加密密码,而是使用散列。Laravel 有自己的关于如何使用它的文档:https ://laravel.com/docs/5.8/hashing


推荐阅读