Reset Your Password from API

By | January 5, 2017

UPDATE 27/4/2018 – New blog post about reset password from an API – LARAVEL: RESET PASSWORD FROM AN API. Much more simpler than this one.

As you may know, Laravel provide a scaffold auth, which include reset/forgot password on web applications side. But what if you have a mobile application that need to reset password from the mobile application?

In this post, I’ll show you how to reset user’s password from an API in Laravel.

UPDATE 02/07/2017:

In case you’re looking for App\Transformers\Json, you basically can create a class called Json in app/Transformers directory.

In the Json class:

<?php

namespace App\Transformers;

class Json
{
    public static function response($data = null, $message = null)
    {
        return [
            'data'    => $data,
            'message' => $message,
        ];
    }
}

Please make sure to composer dumpautoload -o afterward.

UPDATE 27/4/2018 – New blog post about reset password from an API – LARAVEL: RESET PASSWORD FROM AN API. Much more simpler than this one.

27 thoughts on “Reset Your Password from API

    1. guest

      Try import Password class:
      use Illuminate\Support\Facades\Password;

      Reply
  1. Ariel Morningstar

    Hey ther! Thanks for the tutorial, but I’m not quite sure what to do with the token that generates the application. What should I do with that response?
    Thanks in advance

    Reply
  2. nischalrai

    App\Transformers\Json
    not found !
    How do i make it work sir ?

    Reply
  3. Jason

    This needs further user validation.
    Any user can reset the password of another user just by knowing the email address.

    Reply
  4. Adam Tomat

    Question, won’t this allow someone to reset anybody’s password? You probably want the token to be sent to the email still, to validate whether the user is allowed to reset this password.

    Reply
  5. José Carlos de Almeida Júnior

    App\Transformers\Json
    not found !
    How do i make it work sir ?

    Reply
    1. nasrulhazim.m Post author

      ahh..i’m trying to find back where I put my codes for the Transformers part, but couldn’t find it.

      But what it does it’s basically transform from one data structure to another data structure format so that the response will be standard across the application.

      I’ll update my post shortly how to make one Json Transformer based on this article.

      Reply
    1. nasrulhazim.m Post author

      yes, it’s just a POC to make the possibility to reset the password from API – you may need to implement back the way how the web version working OR use 2FA to reset OR use SMS Code to reset the password.

      Reply
  6. Riansyah R

    With the release of Laraven and Lumen 5.5 – Is there a probability where you can make another tutorial of this feature using only Lumen 5.5 stateless API instead? Thank you beforehand.

    Reply
      1. Yousef

        Can you give us example on Notification where to add it? thanks

        Reply
  7. Dhakshan

    User must implement CanResetPassword interface.

    I am getting above error. Is there any solution.

    Reply
    1. nasrulhazim.m Post author

      I’ve update in code snippet above.

      Anyway, you want much more simpler solution, I just write new blog post –

      Reply
  8. yagnesh

    $response = $this->broker()->reset(
    $this->credentials($request), function ($user, $password) {
    $this->resetPassword($user, $password);
    }
    );

    NOT working and also i cant understood whats saying this code
    please help us.
    Thanks

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

5 + four =