Reset Your Password from API
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 AppTransformersJson
, you basically can create a class called Json
in app/Transformers
directory.
In the Json
class:
<?php namespace AppTransformers; 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.
tnx bro 🙂
$token = $this->broker()->createToken($user);
got error broker not found
Try import Password class:
use Illuminate\Support\Facades\Password;
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
App\Transformers\Json
not found !
How do i make it work sir ?
How and where can I specify different guard user?
$token = $this->broker()->createToken($user);
got error broker not found
This needs further user validation.
Any user can reset the password of another user just by knowing the email address.
yerp, absolutely.
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.
I was also thinking the same 🙂
App\Transformers\Json
not found !
How do i make it work sir ?
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.
This seems highly insecure as Adam Tomat said.
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.
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.
I’ll try to make my time for a new one. 🙂
Thank you, but it is insecure, How can I send token via email ?
You can use Notification, or Mail in Laravel – https://laravel.com/docs/5.5/mail, https://laravel.com/docs/5.5/notifications#mail-notifications
Can you give us example on Notification where to add it? thanks
User must implement CanResetPassword interface.
I am getting above error. Is there any solution.
same problem brother
Transformers/Json not found plz tell me if possible mail me on
[email protected]
I’ve update in code snippet above.
Anyway, you want much more simpler solution, I just write new blog post –
UPDATE 27/4/2018 –
New blog post about reset password from an API. Much more simpler than this blog post.
LARAVEL: RESET PASSWORD FROM AN API – https://blog.nasrulhazim.com/2018/04/laravel-reset-password-from-an-api/
$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
any errors?
I get Unauthenticated as response after reset