Skip to content

Instantly share code, notes, and snippets.

@gravitano
Last active August 29, 2015 13:56
Show Gist options
  • Save gravitano/9223983 to your computer and use it in GitHub Desktop.
Save gravitano/9223983 to your computer and use it in GitHub Desktop.
<?php
$input = Input::all();
$rules = array(
'password' => 'required|min:6|max:20|confirmed',
'password_confirmation' => 'required|min:6|max:20',
'current_password' => 'required'
);
$validation = Validator::make($input, $rules);
if ($validation->passes())
{
if($input['current_password'] == $input['password'])
{
$response = array(
'status' => false,
'message' => 'Your new password can not be same with current password.',
);
}else{
// check old password
$validate = Hash::check($input['current_password'], Auth::user()->getAuthPassword());
if($validate)
{
Auth::user()->update([
'password' => Hash::make($input['password'])
]);
$response = array(
'status' => true,
'message' => 'Your password has been successfully updated.',
);
}else{
$response = array(
'status' => false,
'message' => 'Wrong old password.',
);
}
}
}else{
$response = array(
'status' => false,
'message' => 'There was validation errors.',
'errors' => $validation->errors()->toArray()
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment