プロジェクトの場合、ユーザーがいなくても、データベースに暗号化されたパスワードを保管したいと考えています。だから、Sails.js - パスワードを暗号化
私は、ユーザーを追加するときにパスワードを暗号化する必要があるので、私はあなたの助けが必要ですが、私はsails lift
を起動したとき、私は、端末にエラーがあります。
In model `user`:
The `toJSON` instance method is no longer supported.
Instead, please use the `customToJSON` model setting.
構成:私は
Sails 1.0 Beta
とBcrypt 1.0.2
を使用してください。
モデルuser.jsの
/**
* User.js
*
* @description :: A model definition. Represents a database
table/collection/etc.
* @docs :: https://sailsjs.com/docs/concepts/models-and-
orm/models
*/
var bcrypt = require('bcrypt');
module.exports = {
attributes: {
firstname: {
type: 'string'
},
lastname: {
type: 'string'
},
password: {
type: 'string'
},
email: {
type: 'string',
unique: true
},
code: {
type: 'string',
unique: true
},
referring: {
type: 'string'
},
comment: {
type: 'text'
},
// Add reference to Profil
profil: {
model: 'profil'
},
toJSON: function() {
var obj = this.toObject();
delete obj.password;
return obj;
}
},
beforeCreate: function(user, cb) {
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(user.password, salt, function(err, hash) {
if (err) {
console.log(err);
cb(err);
} else {
user.password = hash;
cb();
}
});
});
}
};
私はパスワードを暗号化するために、古い方法を使用していると思うが、私は知らないか、これを行うための別の方法を見つけることができません。
ありがとうございます。
'bcrypt'はそれだけでひどく命名され、暗号化ではありません。それは実質的なCPUの計算時間を含むパスワード用に設計された暗号化ハッシュ法であり、安全な方法です。要点は、攻撃者が無差別にパスワードを見つけるのに多くの時間を費やすことです。 – zaph