change password user laravel 5.3

前端 未结 5 1513
终归单人心
终归单人心 2021-01-30 11:00

I want to create form with 3 field (old_password, new_password, confirm_password) with laravel 5.

View

old password : {!! Form::password(

5条回答
  •  忘了有多久
    2021-01-30 11:37

    I am explain here another method to change user password changepassword.blade.php

    @extends('layouts.app')
    
    @section('content')
    
    Change password
    @if (session('error'))
    {{ session('error') }}
    @endif @if (session('success'))
    {{ session('success') }}
    @endif
    {{ csrf_field() }}
    @if ($errors->has('current-password')) {{ $errors->first('current-password') }} @endif
    @if ($errors->has('new-password')) {{ $errors->first('new-password') }} @endif
    @endsection

    This is route in web.php

    Route::post('/changePassword','HomeController@changePassword')->name('changePassword');
    

    Controller Method

    public function changePassword(Request $request){
    
            if (!(Hash::check($request->get('current-password'), Auth::user()->password))) {
                // The passwords matches
                return redirect()->back()->with("error","Your current password does not matches with the password you provided. Please try again.");
            }
    
            if(strcmp($request->get('current-password'), $request->get('new-password')) == 0){
                //Current password and new password are same
                return redirect()->back()->with("error","New Password cannot be same as your current password. Please choose a different password.");
            }
    
            $validatedData = $request->validate([
                'current-password' => 'required',
                'new-password' => 'required|string|min:6|confirmed',
            ]);
    
            //Change Password
            $user = Auth::user();
            $user->password = bcrypt($request->get('new-password'));
            $user->save();
    
            return redirect()->back()->with("success","Password changed successfully !");
    
        }
    

    i have follow that link :- https://www.5balloons.info/setting-up-change-password-with-laravel-authentication/

提交回复
热议问题