Laravel应用中的哈希密码并签入另一个密码

问题描述 投票:1回答:2

我有一个系统,其中几个Laravel应用程序将信息上传到各个数据库,可以使用通用Laravel API(系统的核心)来访问这些数据库的信息。我在Laravel应用中使用hash :: make来对密码进行哈希处理,但是我想在Laravel API中对其进行检查,但是当我尝试\ hash :: check密码不匹配时。

这是我的Laravel应用中的哈希码:

            $patient = new patient();
            $patient->username = $request->input('username');
            $patient->password = \Hash::make($request->input('password'));
            $patient->fullname = $request->input('name');
            $patient->note = $request->input('note');
            $patient->save();

这是我的API登录代码:

        $username  = $request->username;
        $password  = $request->password;
        $patient = Patients::where('username','=',$username)->get();
        if (\Hash::check($password, $patient[0]->password))
        {
            return response()->json($patient[count($patient)-1]);
        }else {
            return 0;
        }  

我是在做错什么,还是做不到这样的事情?

谢谢:)

我正在使用Laravel 5.8

php laravel hash laravel-5.8
2个回答
1
投票

我的猜测是,这些应用之间的config/hashing.php配置可能有所不同。此配置有多个选项(例如Bcrypt,Argon2i,Argon2id等]]),并且在存储哈希密码时使用哪个选项,在检查时会很重要。确保它们在不同的应用程序中保持一致。


1
投票

这解决了我的问题:

© www.soinside.com 2019 - 2024. All rights reserved.