美文网首页
md5密码加密

md5密码加密

作者: 奈何明月照沟渠 | 来源:发表于2023-03-22 12:12 被阅读0次

    引入crypto模块

    const crypto = require('crypto')
    
    const d5 = (str)=>{
        return  crypto.createHash('md5').update('dy'+ str).digest('hex')
    }
    module.exports = d5
    

    model中使用

    const md5 = require('../util/md5')
    password:{
            type: String,
            required: true,
            set: val => md5(val)
        },
    

    controller中需要将返回的用户信息中的密码删除

    exports.register = async (req,res) => {
        console.log(req.method);
        const userModel = new User(req.body)
        const dbBack = await userModel.save()
        const user = dbBack.toJSON()
        delete user.password
        res.status(201).json(user)
    }
    

    相关文章

      网友评论

          本文标题:md5密码加密

          本文链接:https://www.haomeiwen.com/subject/hpnvrdtx.html