Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remember Users & Forgot Password Functionality in Laravel 5.1 and Angular JS (JWT Authentication)

I am using laravel 5 and angular js and JWT authentication for logging and registering my users. But there is nothing mentioned about to facilitate users with remember me functionality and also allow users to reset password when forgotten password.

I researched a lot and didn't find exactly what I need though the answer in following link is helpful but inadequate for me to proceed. Laravel 5 Password Reset with Angular View

Kindly provide any information and links that would be helpful. Thanks in advance! :)

like image 933
Shraddha Banerjee Avatar asked Sep 25 '15 13:09

Shraddha Banerjee


People also ask

How does remember functionality work?

Clicking the “Remember Me” box tells the browser to save a cookie so that if you close out the window for the site without signing out, the next time you go back, you will be signed back in automatically. Make sure that you have your browser set to remember cookies, or this function will not work.

What is Remember checkbox?

Remember Me? was checked you can leave the webpage without logging out and then be logged back in automatically if you visit the page again within the session timeout period (default is 30 minutes).

What are user names and passwords?

A username is almost always paired with a password. This username/password combination is referred to as a login, and is often required for users to log in to websites. For example, to access your e-mail via the Web, you are required to enter your username and password.


2 Answers

To Answer from a JWT perspective.

Remember me is essentially asking the user how long they want to login for. Depending on the security requirements and typical usage patterns of your users, short sessions are often from 15 minutes and up to a browser session. Long sessions (selecting Remember me) can be anything from 24hours to a year.

The JWT issuer can set the exp claim (expiration time of the token) differently depending on the user's selection of the 'Remember Me' checkbox.

If you're intending the 'Remember Me' to last longer than a single browser session, the simplest way is to store the token in a cookie. This means the cookie also needs to have the following properties set: httponly, secure, and expires (with the same expiry time as the exp claim from the token).

Rest Password implementations come in many shapes and sizes depending on your requirements. These are not directly related to JWTs as they come before the JWT issuer will issue a token.

like image 101
Alex Avatar answered Sep 28 '22 01:09

Alex


You're asking for something that will need to be handled specifically for your case. The way most "remember me" systems work (including Laravel) is via storing a cookie on the user's device. That cookie is then used to authenticate automatically when the user returns. JWT is different as you are given a token, rather than a cookie, that you pass back to the server in a header. They are both essentially strings of letters and numbers, but you'll specifically have to store the JWT token on the user's browser in order for a "remember me" type of functionality. You might do this in the Angular app using localStorage or some other similar front-end practice.

For the forgotten password, you can submit the same form fields that are default to Laravel and simply override how the PasswordController returns the response; in this case needing a JSON response rather than a redirect.

like image 35
Adam Kelso Avatar answered Sep 27 '22 23:09

Adam Kelso