So überprüfen Sie die aktuelle, neue, und neues Passwort Bestätigung in Laravel 5?

Ich habe das Kennwort route, Ansicht und Methode in UserController@getProfilePassword und UserController@postProfilePassword

In dem moment, wenn ich füllen Sie das new_password Feld, es wird ein Hashwert und übermittelt, korrekt in der Datenbank, dann kann ich mit dem neuen Passwort einloggen.

Aber ich muss in der Lage sein zu überprüfen, die new_password und new_password_confirm um sicherzustellen, dass Sie identisch sind und überprüfen Sie den Benutzer das aktuelle Kennwort als gut.

Wie kann ich das tun?

EDIT: ich Hinzugefügt $this->validate zu der Methode, aber jetzt bekomme ich immer den Fehler The password confirmation confirmation does not match. auch wenn Sie nicht übereinstimmen, wie ich bin, mit einem einfachen Passwort. Auch ich denke, dass ich brauchen, um zu überprüfen, die gegen das aktuelle Kennwort manuell als validator wird es nicht tun für mich.

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

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

    $this->validate($request, [
        'old_password'          => 'required',
        'password'              => 'required|min:4',
        'password_confirmation' => 'required|confirmed'
    ]);

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

- Und dies ist die Ansicht

<form action="{{ route('profile/updatepassword') }}" 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="password" class="form-control" id="password">
    </div>
    <div class="form-group">
          <label for="name">New Password</label>
          <input type="password" name="password_confirmation" class="form-control" id="password_confirmation">
    </div>
    <button type="submit" class="btn btn-primary">Change Password</button>
    <input type="hidden" value="{{ Session::token() }}" name="_token">
 </form>
InformationsquelleAutor Halnex | 2016-06-01
Schreibe einen Kommentar