So I'm having a few issues with allowing the user to change their own password.
Now, I've gotten it to work so that it does actually change the current user's password since I see it change within the Database. However! What it's not doing is allowing the user to login through this new password. Nor does it allow them to use this new password to change because it's not recognising the new passoword. It's as if Laravel does not recognise this new password..
View:
<?php
<div class="panel panel-default">
<div class="panel-heading">Change Your Password</div>
{{ Form::open(array('url' => 'security/change_password')) }}
<div class="form-group">
{!! Form::label('current_password', 'Enter Current Password:') !!}
{!! Form::text('current_password', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('password', 'Enter New Password:') !!}
{!! Form::text('password', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('password_confirmation', 'Confirm New Password:') !!}
{!! Form::text('password_confirmation', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('Change Password', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
</div>
?>
Controller:
<?php
public function updatePassword(UserSecurityFormRequest $request)
{
$user = Auth::user();
$current_password = $request->input('current_password');
$new_password = $request->input('password');
if (!Hash::check($current_password, $user->password)) {
return back()->withErrors('Please specify the good current password');
}
else{
$user->password = Hash::make($new_password);
$user->save();
}
}
?>
I have also tried this:
Controller V2
public function updatePassword(UserSecurityFormRequest $request)
{
$user = Auth::user();
$current_password = $request->input('current_password');
$new_password = $request->input('password');
if (!Hash::check($current_password, $user->password)) {
return back()->withErrors('Please specify the good current password');
}
else{
$user->password = bcrypt($new_password);
$user->save();
}
}
No such luck :/
Then I tried this in my controller:
public function updatePassword(UserSecurityFormRequest $request)
{
$user = Auth::user();
$current_password = $request->input('current_password');
$new_password = $request->input('password');
if (!Hash::check($current_password, $user->password)) {
return back()->withErrors('Please specify the good current password');
}
else{
$user->fill([
'password' => Hash::make($request->newPassword)
])->save();
}
}
Again. As before, it changed the password but then when I went to change it again through the form; it did not recognise the changed password.
Request:
<php
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class UserSecurityFormRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'current_password' => 'required|min:6',
'password' => 'required|min:6|confirmed',
];
}
}
?>
Now, a few places suggested setting an attribute for password like so:
<?php
public function setPasswordAttribute($password)
{
return $this->attributes['password'] = bcrypt($password);
}
?>
^I didn't have much luck with that. If any :/
I know the code (esp in the controller) is rather messy but I'll sort that out once I've fixed the functionality.
Any help would be highly appreciated
Best regards
Friaku