Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.ensurePasswordSalt = function (user, body) {
if (!user.password_sha && body.password) {
// create password_sha on server
user.salt = crypto.randomBytes(30).toString('hex');
user.password_sha = utility.sha1(body.password + user.salt);
}
};
co(function * () {
var user = yield UserModel.find({where: {name: username}});
var salt = user.salt;
console.log(`user original password_sha: ${user.password_sha}`);
var newPasswordSha = utility.sha1(newPassword + salt);
user.password_sha = newPasswordSha;
user = yield user.save();
console.log(`change user password successful!! user new password_sha: ${user.password_sha}`);
process.exit(0);
}).catch(function (e) {
console.log(e);
createPasswordSha: function (password, salt) {
return utility.sha1(password + salt);
},
function passwordSha(password, salt) {
return utility.sha1(password + salt);
}
checkSignature: function (signature, timestamp, nonce) {
var oriArray = new Array();
oriArray[0] = nonce;
oriArray[1] = timestamp;
oriArray[2] = global.wx.token; //这里是你在微信开发者中心页面里填的token
oriArray.sort();
var original = oriArray.join('');
var cyptoString = utility.sha1(original);
return signature == cyptoString;
}
};