Sqlite如何转义值以防止SQL注入

有谁可以告诉我如何转义input值,以防止SQL注入? 我有一个用户身份validation应用程序,我需要以某种方式导入一些安全性。

我的validation看起来像这样:

//Validation req.checkBody('name', 'Name is required').notEmpty(); req.checkBody('email', 'Email is required').notEmpty(); req.checkBody('email', 'Email is not valid').isEmail(); req.checkBody('password', 'Password is required').notEmpty(); req.checkBody('password', 'Password must have at least 6 characters').len(6,20); req.checkBody('password2', 'Passwords do not match').equals(req.body.password); 

然后我INSERT一些值如下:

 var stmt = db.prepare("INSERT INTO users ( id, name, email, password, salt) VALUES (NULL, ?, ?, ?, ?)"); stmt.run([ name, hashEmail(email,'salt'), hashPassword(password,'salt'), 'salt'], function(error){ //..... 

我被告知这不是真正安全的方法来import价值,但只要我没有真正的互联网安全经验,我会需要你的一些帮助。

问候

由于您已经正确使用了参数化查询(而不是构造一个与请求参数混合的SQLstring,所以您在查询中使用了?来指定执行SQL语句时参数将被replace的位置),则上面显示的代码已经罚款和不容易SQL注入

如果您将这些variables与SQLstring本身连接起来,那么它只会受到SQLi的攻击。