1.新建了一个setPassword.js文件
const crypto = require("crypto"); ///导入加密模块 function setPassword(pwd){ let password=`${pwd}xxx` //加入一段特定字符 防止解密 const md5 = crypto.createHash('md5'); md5.update(password); var newpwd=md5.digest('hex'); return newpwd } module.exports=setPassword
2.在程序中使用
const { query } = require('express'); const uuid = require('uuid') const connection = require('../lab/connectMysql') const express = require('express'); const router = express.Router(); const setPassword = require('../lab/setPassword') connection.connect() //登录账户 router.post('/login', function (req, res, next) { // console.log(req.body) let { username, password} = req.body; let userid = uuid.v1(); let password2=setPassword(password) //在此使用 console.log(username, password2,userid); })
标签:const,nodejs,require,express,密码,let,setPassword,加密,password From: https://www.cnblogs.com/banyuege/p/16856260.html