php - 如何解密密码以登录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 有人可以帮忙吗?
解决方案
不要加密密码,而是使用散列。Laravel 有自己的关于如何使用它的文档:https ://laravel.com/docs/5.8/hashing
推荐阅读
- reactjs - 将地图数据组合传递到我的组件卡
- javascript - 运行函数的函数 onclick 事件侦听器
- laravel - 在非新鲜的 laravel 中安装 laravel/ui 和 auth
- docker - docker 使用什么库在终端上呈现拉取/下载/提取信息
- google-calendar-api - 如何为自定义持续时间加载谷歌 ics 文件?
- java - 在链表的最后一个索引位置添加元素时面临的问题
- python - 我可以通过 CBV 创建用户实例而不是先创建表单吗?(姜戈)
- c# - 如何关闭程序
- javascript - jQuery ajax 不适用于加载窗口
- c# - 将多页 JSON 反序列化为单个对象?