Laravel强制用户在第一次登录时更改密码



Laravel 5.6(5.7(在首次尝试登录时强制更改密码

在我的项目中,我通过从excel导入所有用户的默认/通用密码来批量上传用户

问题是,我必须编写一个脚本,强制所有用户在第一次登录时更改密码。

解决方案是,我必须添加"password_changed_at";列,在我的家庭控制器索引中,我在下面添加了这个代码(因为每个新用户都指向家庭(

public function index()
{   
if ((Auth::user()->password_change_at == null)) {
return redirect(route('change-password'));
}
else{

return view('home');    
}

}

我确实使用了laravel设置更改密码的更改密码但是我添加了一个低于的代码更新

//Change Password
$user = Auth::user();
$user->password = Hash::make($request->get('new-password'));
$user->password_change_at = CarbonCarbon::now(); //add new line of code
$user->save();

最新更新