dbに暗号化値を挿入しようとしましたが、暗号化された値をdbに挿入できない値を暗号化できます。ノードjsの暗号化
app.post('/insert', function (req, res) {
// var Fname=req.body.fname;
// var Lname=req.body.pwd;
var data = {
Fname: req.body.fname,
Lname: req.body.Lname
};
function hashP(getit, cb) {
bcrypt.genSalt(15, function (err, salt) {
if (err) {
return console.log(err);
}
cb(salt);
bcrypt.hash(getit, salt, function (err, gotit) {
if (err) throw err;
return this.cb(null, gotit);
})
})
}
hashP(data.Lname, function (err, gotit) {
if (err) throw err;
data.Lname = hash;
})
console.log(data.Lname);
con.query("insert into test set ?", [data], function (err, rows) {
if (err) throw err;
res.send("Value has bee inserted");
})
})
これは私のHTMLフォームのページです:
<body>
<form action="http://localhost:8888/insert" method="POST" >
<label>Name:</label><input type="text" name="fname"></br>
<label>Lname:</label><input type="text" name="Lname"></br>
<button type="submit">Submit</button>
</form>
</body>
エラーは何ですか? –
私は、DBに直接挿入されたHTMLフォームから来たデータにエラーはありませんでした。しかし、それは暗号化データとして変換されません。そして私がターミナルをチェックインすると、2つのLname値を取得しています.1つは直接データで、もう1つは暗号化されたデータです。 – chozhan
'hash'はどこにも定義されていないので、これは間違っています:' data.Lname = hash; '代わりに 'gotit'を使用するのですか? – jfriend00