安全涉及
sql注入
使用mysql.escape
const sql = `select username, realname from users where username='${escape(username)}' and password='${escape(password)}'`
xss攻击
使用工具预防即可
const title = xss(blogData.title)
密码加密
自行定义加密规则:
保持一致即可
const crypto = require('crypto')
// 密匙
const SECRET_KEY = '@#SUNsih)Ua(a>?'
// md5加密
function md5(content) {
const md5 = crypto.createHash('md5')
return md5.update(content).digest('hex')
}
function genPassword(password) {
let str = `password=${password};<>${SECRET_KEY}`
return md5(str)
}
console.log(genPassword('123'))
module.exports = {
genPassword
}