mardi 31 mai 2016

How to validate current, new, and new password confirmation in Laravel 5?

I have created the password route, view and method in UserController@getProfilePassword and UserController@postProfilePassword

At the moment, if I fill out the new_password field, it gets hashed and submitted to the database correctly, then I can login with the new password.

But I need to be able to validate the new_password and new_password_confirm to make sure they're the same and validate the user's current password as well.

How can I do that?

public function getProfilePassword() {
    return view('profile/password', ['user' => Auth::user()]);
}

public function postProfilePassword() {
    $user = Auth::user();

    $user->password = Hash::make(Input::get('new_password'));
    $user->save();
}

And this is the view

<form action="" method="post" enctype="multipart/form-data">
    <div class="form-group">
          <label for="name">Current Password</label>
          <input type="password" name="old_password" class="form-control" id="old_password">
    </div>
    <div class="form-group">
          <label for="name">Password</label>
          <input type="password" name="new_password" class="form-control" id="new_password">
    </div>
    <div class="form-group">
          <label for="name">New Password</label>
          <input type="password" name="new_password_confirm" class="form-control" id="new_password_confirm">
    </div>
    <button type="submit" class="btn btn-primary">Change Password</button>
    <input type="hidden" value="" name="_token">
 </form>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire