現在、次の設定を使用して新しいユーザーを登録しています。
// creates a new user
app.post('/users', function(req, res) {
// create new user
var user = new User();
// assign post
user.username = req.body.username;
user.email = req.body.email;
crypto.randomBytes(32, function(err, buf) {
if (err) throw err;
user.salt = buf.toString('hex');
crypto.pbkdf2(req.body.password, user.salt, 25000, 512, function(err, encodedPassword) {
if (err) throw err;
user.password = (encodedPassword.toString('hex')); // this line
user.save(function(err, user) {
if (!err) return res.send(err, 500);
return res.json(user);
});
}.bind(this));
});
});
この行を詳しく見てください。
user.password = (encodedPassword.toString('hex'));
これにより、パスワード文字列 (バイナリのように見える) が 16 進文字列にエンコードされます。何らかの理由でこれは機能しません。
なぜだめですか?
Byside : ソルトとパスワードの保存に推奨されるエンコーディング (hex、binary、base64) は?