Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //password change controller
- const passwordChangeController = async (req,res) => {
- try{
- const passwordValidator = Joi.object({
- password: Joi.string().required().pattern(new RegExp ('^[a-zA-Z0-9]{8,30}$'))
- })//validator the password
- const {error} = passwordValidator.validate(req.body)
- if(error){
- res.json({
- message: "validation error",
- error
- })
- }else{
- const {id} = req.params;
- const {password} = req.body;
- const hash = await bcrypt.hash(password, 10)
- await User.findByIdAndUpdate(
- {_id : id},
- {
- $set: {
- password: hash
- }
- }
- )
- return res.json({
- message: "password has been changed"
- })
- }
- }
- catch(err){
- res.json({
- err
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement