When the user selects his reset his password, you can send an email to the user with a link containing a token associated with the user. As soon as the user clicks on the link, you check the user based on the token and email, and then show the reset HTML code. When the user enters a new password, in the base code you set the password in the User object after hashing, and then save it. You can also set the token to zero.
Sample code with base 64 will be as shown below
user.salt = new Buffer(crypto.randomBytes(16).toString('base64'), 'base64'); user.password = user.hashPassword('newPassword'); user.token = undefined; user.save(...)
The hashPassword method is used.
UserSchema.methods.hashPassword = function(password) { if (this.salt && password) { return crypto.pbkdf2Sync(password, this.salt, 10000, 64).toString('base64'); } else { return password; } };
The above code is auto generated using Yeoman
source share