Created
October 21, 2022 08:01
-
-
Save Octagon-simon/4214f9c14f5bce0e385691e5655c27d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//generate password reset hash | |
userSchema.methods.generatePasswordResetHash = function(){ | |
//create hash object, then create a sha512 hash of the user's current password | |
//and return hash | |
const resetHash = crypto.createHash('sha512').update(this.password).digest('hex') | |
return resetHash; | |
} | |
//verify password reset hash | |
userSchema.methods.verifyPasswordResetHash = function(resetHash = undefined){ | |
//regenerate hash and check if they are equal | |
return this.passwordResetHash() === resetHash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment