Suddenly in my console it's start giving errors, and it has been running fine for days without any change. Please advise.
/node_modules/mysql/lib/protocol/Parser.js:82
throw err;
^
TypeError: Not a buffer
at TypeError (native)
at pbkdf2 (crypto.js:607:20)
at Object.exports.pbkdf2Sync (crypto.js:590:10)
crypto: require("crypto"),
encrypt: function(password) {
var salt = this.getSalt(password, this.constructor.GUID);
return {salt: salt, password: this.getEncrypted(password, salt)};
},
getSalt: function(password, GUID) {
return this.crypto.createHash("sha256").update(password + "|" + GUID).digest("hex")
},
getEncrypted: function(password, salt) {
return this.crypto.pbkdf2Sync(password, salt, 4096, 512, "sha256").toString("hex");
},
verifyPassword: function(user, password) { //var salt = this.getSalt("test@test.com|" + this.constructor.GUID); console.log("salt: " + salt); console.log("password: " + this.getPassword("HUG2015", salt));
return this.crypto.pbkdf2Sync(password, user.salt, 4096, 512, "sha256").toString("hex") == user.password; //test
},
generateAuthToken: function() {
return this.crypto.randomBytes(64).toString("hex");
}
Edit: Usage
getUser: function(emailAddress, password) {
var self = this;
this.connection.query("SELECT * from admin WHERE emailAddress = ?", [emailAddress], function(error, rows, fields){
if(error) {
self.onFault({status: 500, body: error});
} else {
if(rows.length == 1) {
self.verifyPassword(rows[0], password)
} else {
self.onFault({status: 401, body: {}});
}
}
});
},
verifyPassword: function(user, password) {
var self = this;
try {
if(this.authenticationProxy.verifyPassword(user, password)) {
this.setAuthToken(user, this.authenticationProxy.generateAuthToken());
} else {
this.onFault({status: 401, body: {}});
}
} catch(exception) {
this.onFault({status:500, body: exception});
}
},