2016-04-29 3 views
0

Hey Leute Ich versuche, eine Änderung Passwort-Funktion, wo der Benutzer sein eigenes Passwort durch Kenntnis der courrent Passwort ändern können. Das Problem steht, wenn ich die Werte zu vergleichen um die Passwörter zu entsprechen sie nicht eaven obwohl ich die gleichen Werte.Ich füge Benutzer ab, die Panel mit einem Standardwert im Passwortfeld, das ist bcrypted Wert von 'admin1234' .Wenn ich mit diesem Passwort anmelden Alles ist in Ordnung. Dann gehe ich in das Passwort ändern Feld ... das Passwort aus dem Formular abrufen ... verschlüsseln und vergleichen Sie dann ... es stellt sich heraus, es ist ein anderer Wert ... Ich eaven echo -ed sie und in der Tat sind sie eine andere Werte ... Ich vermisse etwas hier ??Passwort-Werte in bcrypt beim Vergleich in Laravel nicht

aktualisieren Passwort-Funktion:

public function change_password(Request $request, $id) 
    { 
     $this->validate($request, array(
      'courrent_password'=>'required|max:255', 
      'new_password'=>'required|max:255' 
     )); 

     $user = User::find($id); 
     if($user->password == bcrypt($request->courrent_password)) 
     { 
      /*$user->password = $request->new_password; 

      if($user->save()) 
      { 
       return redirect(route('user_profile',$id))->with('success', sprintf('Password successfully saved.'));} 
      else if ($validation->fails()) 
      { 
       return redirect(route('user_profile',$id.'#tab_1-3')); 
      }*/ 
     } 
     else 
     { 
      echo bcrypt($request->courrent_password).' new password'; 
      echo'<br><br>'.$user->password.' password'; 
      //return redirect(route('user_profile',$id.'#tab_1-3'))->with('error', sprintf("Current password doesn't match")); 
     } 
    } 

aktualisieren Passwort Form:

{!! Form::open(array('route' => ['change_password',$user-> id],'id' => 'form_sample_2','class'=>'form-horizontal','novalidate' => 'novalidate','role' => 'form')) !!} 
             {!! csrf_field() !!} 
             <div class="form-body"> 
              <div class="alert alert-danger display-hide"> 
               <button class="close" data-close="alert"></button> You have some form errors. Please check below. </div> 
              <div class="alert alert-success display-hide"> 
               <button class="close" data-close="alert"></button> Your form validation is successful! </div> 
              <div class="form-group"> 
               <label class="control-label col-md-3">Courrent Password 
                <span class="required" aria-required="true"> * </span> 
               </label> 
               <div class="col-md-4"> 
                <input type="password" name="courrent_password" data-required="1" id="courrent_password" class="form-control"> 
               </div> 
              </div> 
              <div class="form-group"> 
               <label class="control-label col-md-3">New Password 
                <span class="required" aria-required="true"> * </span> 
               </label> 
               <div class="col-md-4"> 
                <input type="password" name="new_password" data-required="1" id="password" class="form-control"> 
               </div> 
              </div> 
              <div class="form-group"> 
               <label class="control-label col-md-3">Retype Password 
                <span class="required" aria-required="true"> * </span> 
               </label> 
               <div class="col-md-4"> 
                <input type="password" name="repassword" data-required="1" id="repassword" class="form-control" onkeyup="checkPass(); return false;"> 
                <span class="help-block" id="checkpass"></span> 
               </div> 
              </div> 
             </div> 
             <div class="form-actions"> 
              <div class="row"> 
               <div class="col-md-offset-3 col-md-9"> 
                <button type="submit" id="submit" class="btn green">Submit</button> 
                <button type="button" class="btn grey-salsa btn-outline">Cancel</button> 
               </div> 
              </div> 
             </div> 
             {!! Form::close() !!} 

dies sind die Ergebnisse Echo-ed

$2y$10$2S/6BBrBdxe9FHzjH33g0elCgjUov4Pq7EBkRwE.n2JkbvCwHXPFC new password 

$2y$10$55V3ZfdbDOutDUZKO3q6nezntlQqYqqiyhVhwTPEnWuZmy.8/QxYG password 

Antwort

0

Verwendung dieses:

if(Auth::attempt(['email' =>Auth::user()->email, 'password'=>$request['courrent_password']])) 

anstelle davon:

if($user->password == bcrypt($request->courrent_password))