Last active
August 29, 2015 13:56
-
-
Save gravitano/9223983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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