For Accounts.forgotPassword()
and Accounts.sendVerificationEmail()
, a token is generated.
Does that token ever expire?
If so, after what period of time?
By default, password reset tokens expire after one hour. You may change this via the password reset expire option in your config/auth. php file. The default expire is 60 minutes.
Well-engineered password reset processes will automatically expire or invalidate the password reset URL after a period of time. In some cases, the expiration window may be aggressive, and it's possible the link will expire before the recipient has an opportunity to check their email and reset their password.
If you experience an error message that states "Token Expired", this is letting you know the system has timed out and will need to be refreshed.
At the moment there is no built-in code that relates to token expiration, neither setting an expiration time nor enforcing it.
The email reset data (token, email and token creation date) is saved in the user's record, as can be seen in the source:
var tokenRecord = {
token: token,
email: email,
when: when
};
Meteor.users.update(userId, {$set: {
"services.password.reset": tokenRecord
}});
Therefore, the date is in the following mongo selector:
'services.password.reset.when'
Unfortunately, all of the reset
data is unset as soon as the resetPassword
method is called with the correct token.
This makes it unavailable to the validateLoginAttempt
callbacks:
Accounts.validateLoginAttempt(function(options) {
if (options.methodName === 'resetPassword' && options.allowed === true) {
console.log('resetPassword', options.user.services.password.reset); //undefined
}
return true;
});
Similarly, the email verification token is stored in user.services.email.verificationTokens
, which (if set) is an array of token records.
The dates are, therefore, in
'services.email.verificationTokens.when'
You could, however, invalidate old tokens periodically quite easily with this info, or roll your own local fork or wrap of accounts-password.
With the current version of Meteor (1.9), tokens do expire, as you can see here in the code (and I guess it has been the case for quite a long time).
Reset password tokens expire after 3 days, when enroll tokens expire after 30 days
These two parameters are configurable using :
Accounts.config({
passwordResetTokenExpirationInDays : 10,
passwordEnrollTokenExpirationInDays : 60,
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With