如何制作散列密码 laravel 6
How to make hashed passwords laravel 6
我创建了一个表单,管理员可以在其中注册系统上的帐户。问题是在管理员端创建用户时密码没有经过哈希处理,我认为这就是阻止用户登录系统的原因。你有什么建议让我完成这项工作吗?我是 Laravel 的新手所以。
我认为问题出在这段代码中..
public function store(Request $request)
{
$this->validate(request(), [
'firstname' => 'required|string|max:255',
'lastname' => 'required|string|max:255',
'username' => 'required|string|max:25|unique:users',
'phone' => 'required|string|max:12|min:11|unique:users',
'address' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:8|confirmed',
'membership_term' => 'required|string|max:255',
'mode_of_payment' => 'required|string',
]);
$user = new User;
$user->firstname = $request->input('firstname');
$user->lastname = $request->input('lastname');
$user->username = $request->input('username');
$user->phone = $request->input('phone');
$user->address = $request->input('address');
$user->email = $request->input('email');
$user->password = $request->input('password');
$user->membership_term = $request->input('membership_term');
$user->mode_of_payment = $request->input('mode_of_payment');
$user->save();
return back()->with('success', 'Data Updated.')->with('users', $user);
}
试试这个
use Illuminate\Support\Facades\Hash;
$user->password = Hash::make($request->input('password'));
您可以使用 laravel 辅助函数 bcrypt()
$user->password = bcrypt($request->input('password'));
我创建了一个表单,管理员可以在其中注册系统上的帐户。问题是在管理员端创建用户时密码没有经过哈希处理,我认为这就是阻止用户登录系统的原因。你有什么建议让我完成这项工作吗?我是 Laravel 的新手所以。
我认为问题出在这段代码中..
public function store(Request $request)
{
$this->validate(request(), [
'firstname' => 'required|string|max:255',
'lastname' => 'required|string|max:255',
'username' => 'required|string|max:25|unique:users',
'phone' => 'required|string|max:12|min:11|unique:users',
'address' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:8|confirmed',
'membership_term' => 'required|string|max:255',
'mode_of_payment' => 'required|string',
]);
$user = new User;
$user->firstname = $request->input('firstname');
$user->lastname = $request->input('lastname');
$user->username = $request->input('username');
$user->phone = $request->input('phone');
$user->address = $request->input('address');
$user->email = $request->input('email');
$user->password = $request->input('password');
$user->membership_term = $request->input('membership_term');
$user->mode_of_payment = $request->input('mode_of_payment');
$user->save();
return back()->with('success', 'Data Updated.')->with('users', $user);
}
试试这个
use Illuminate\Support\Facades\Hash;
$user->password = Hash::make($request->input('password'));
您可以使用 laravel 辅助函数 bcrypt()
$user->password = bcrypt($request->input('password'));