在 Laravel 应用程序中散列密码并签入另一个应用程序
Hash password in a Laravel app and check in another one
我有一个系统,其中几个 Laravel 应用程序将信息上传到个人数据库,这些数据库的信息可以通过通用 Laravel API 访问,这是该系统的核心系统。
我在我的 Laravel 应用程序中使用 hash::make 来散列我的密码,但我想在我的 Laravel API 中检查它们,但是当我尝试 \hash::check the passwords don '匹配。
这是我的 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;
}
我是做错了什么还是我不能做那样的事情?
谢谢 :)
I'm using Laravel 5.8
我的猜测是,您的 config/hashing.php
可能在这些应用程序之间进行了不同的配置。此配置有多个选项(例如 Bcrypt、Argon2i、Argon2id 等...),在存储散列密码时使用哪个选项,在检查时很重要。确保它们在不同的应用程序中保持一致。
这解决了我的问题:
"You can do this, but each of your Laravel apps need to have the same APP_KEY= in .env and config/app.php"
我有一个系统,其中几个 Laravel 应用程序将信息上传到个人数据库,这些数据库的信息可以通过通用 Laravel API 访问,这是该系统的核心系统。 我在我的 Laravel 应用程序中使用 hash::make 来散列我的密码,但我想在我的 Laravel API 中检查它们,但是当我尝试 \hash::check the passwords don '匹配。
这是我的 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;
}
我是做错了什么还是我不能做那样的事情?
谢谢 :)
I'm using Laravel 5.8
我的猜测是,您的 config/hashing.php
可能在这些应用程序之间进行了不同的配置。此配置有多个选项(例如 Bcrypt、Argon2i、Argon2id 等...),在存储散列密码时使用哪个选项,在检查时很重要。确保它们在不同的应用程序中保持一致。
这解决了我的问题:
"You can do this, but each of your Laravel apps need to have the same APP_KEY= in .env and config/app.php"