node防止sql注入 xss攻擊和密碼加密


1.sql注入:竊取數據庫內容

select * from users where username='李四'  -- '  and password =''123'  //不用密碼登錄

select * from users where username='李四';delete from users; -- ' and password =''123'  //直接刪除用戶

可以使用escape:mysql.escape

使用: username = escape(username)


2.xss攻擊:竊取前端Cookie內容 node中使用xss插件

引用: const xss = require('xss');
使用: xss(對應要防御的內容)
  


3.密碼加密:保障用戶信息安全

nodejs 自帶的加密 crypto
//引用:
const crypto = require('crypto');

//定義密匙
const SECRET_KEY = 'Lhsuper_685#@'

//md5加密

function md5(content){
    let md5 = crypto.createHash('md5');
    return md5.update(content).digest('hex');
}

//加密函數
function genPassword(password){
    const str = `password = ${password}&key=${SECRET_KEY}`
    return md5(str)
}

使用:genPassword('123')

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM