Categories

Wednesday, April 24, 2024
#919814419350 therichposts@gmail.com
Laravel 6Php

Laravel 6 change user password complete working code

laravel change user password

Hello to all, welcome to therichpost.com. In this post, I will tell you, Laravel 6 change user password complete working code.

laravel change user password
laravel change user password

Post Working:

In this post, I am doing, login user can change his/her password and I am doing this in Laravel 6. I will share, blade, route and controller code in this post.

Here is the working code snippet and please use carefully:

1. Here is the blade template file code:

@if(session()->has("message"))
   <div class="alert alert-success">
   <p> {{session("message")}} </p>
   </div>
@endif
@foreach ($errors->all() as $error)
  <div class="alert alert-danger">
  <p>{{ $error }}</p>
  </div>
@endforeach
<form action="{{ URL::to('/change-password') }}" method="post">
  {{ csrf_field() }}
  <div class="form-group">
      <label for="image"><strong>Change Password:</strong></label>
      <input type="password" class="form-control" id="password" placeholder="New Password" name="password" required>
      <input type="password" name="objectId" value="{{ encrypt(Auth::user()->id) }}" style="display: none;">
  </div>
  <button type="submit" class="btn btn-warning">Submit</button>
</form>

2. Here is the route code:

Route::post('/change-password','HomeController@changePassword');

3. Here is the controller code:

...
use Validator;
...
public function changePassword(Request $request)
    {           
      $validator = Validator::make($request->all(), [

      'password' => 'required|max:255'
      ]);

      if ($validator->fails()) {
      return redirect()->back()
      ->withErrors($validator)
      ->withInput();
            }  

            $reset_password = DB::table('users')->where('id',decrypt(Input::get('objectId')))->update(['password' => bcrypt(Input::get('password'))]);    
            return Redirect::to('home')->with("message","Successful!! Password has been changed");
    }

 

 

This is it, If you have any query then please do comment below.

Jassa

Thank you

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

4 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.