like this
$encrypted = Crypt::encrypt('password_name_variable');
Basically, what you want to do is:
users
Users with a given username in the table. So, you want to first query for users with a given username. Then, after retrieving the user and verifying its existence, you can check if the provided password matches the hashed password on the retrieved model.
public function login(Request $request): Response { $user = User::where('username', $request->get('username')); if (!$user || !Hash::check($request->get('password'), $user->password)) { return back()->with([ 'message' => '用戶名和/或密碼不正確。', 'alert-type' => 'error' ]); } $request->session()->put('user', $user); return redirect('dashboard'); }
However, there are built-in functions in Laravel to achieve this, and depending on your needs, it may be simpler to do this:
public function login(Request $request): Response { if (!Auth::attempt(['username' => $request->get('username'), 'password' => $request->get('password')]) { return back()->with([ 'message' => '用戶名和/或密碼不正確。', 'alert-type' => 'error' ]); } return redirect('dashboard'); }
https://laravel.com/api/8.x/Illuminate/Support/Facades/Auth.html#method_attempt