When I register a new user in a Laravel structure, I now do it like this,
$user = new User;
$user->firstname = $data['firstname'];
$user->lastname = $data['lastname'];
$user->email = $data['email'];
$user->password = bcrypt($data['password']);
$user->save();
This works great and I can log in to the app. However, I want the user to be able to change their passwords on the settings page. Having done this, I used the same technique using
$newPass = bcrypt($response->new_password);
and update the user field. However, after that, I can not enter? I use the built-in authentication service in laravel for registration / login.
What am I doing wrong here? and should I do it differently?
I also tried to encrypt my current password, and I received a completely different hash than the one stored in the database.
This is so confusing.
Updated using controller code,
$this->validate($request, [
'email' => 'email',
'password' => 'min:8|confirmed',
'current_password' => 'required',
]);
$userId = Auth::id();
if(!Auth::attempt(['id' => $userId, 'password' => $request->current_password]))
{
return redirect('settings')->with('alert','current password is wrong.');
}
if($request->email)
{
$data['email'] = $request->email;
}
if($request->password)
{
$data['password'] = bcrypt("helloworld");
}
$user = User::where('id',$userId)->update($data);
dd($data);
Dump data for inputs,
+request: ParameterBag {
"_token" => "JQIIuCjiKQmbK0X5zCM6czYD1vIoh4PGjLO4qrFm"
"email" => "testing@gmail.com"
"password" => "thisisnewpass"
"password_confirmation" => "thisisnewpass"
"current_password" => "helloworld"
]
}