Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.setWallsSecurity = function (wallid, security, callback)
{
//encrypt the password with bcrypt
if(security.password.length > 0)
{
var salt = bcrypt.gen_salt_sync(10);
security.password = bcrypt.encrypt_sync(security.password, salt);
}
async.waterfall([
function (callback)
{
// Get the data from MySQL
client.query("SELECT * FROM `primarywall`.`wall` WHERE `wallID` = ?", [wallid], callback)
},
// Edit the data from MySQL and write to MySQL
function (results, fields, callback)
{
if (results.length == 1)
{
var wallSecurity = security;
app.get("/", function(req, res) {
var salt = bcrypt.gen_salt_sync(10);
var hash = bcrypt.encrypt_sync("B4c0/\/", salt);
if (bcrypt.compare_sync("B4c0/\/", hash))
res.send("hello from express");
else
res.send("");
});
adminUserModel.findOne({'username': username}, function(err, adminUserData) {
if (err) {
console.log('Unable to check if admin user exists because: ' + err);
oReady('Unable to check if user exist', null);
} else {
if (adminUserData) {
var salt = bcrypt.gen_salt_sync(10);
adminUserData.passwordHash = bcrypt.encrypt_sync(password, salt);
} else {
adminUserData = new adminUserModel();
adminUserData.username = username;
var salt = bcrypt.gen_salt_sync(10);
adminUserData.passwordHash = bcrypt.encrypt_sync(password, salt);
}
adminUserData.save(function(err) {
if (err) {
console.log('Unable to create or update admin user because: ' + err);
onReady('Unable to create or update admin user', null);
} else {
adminUser.fields = adminUserData;
onReady(null, adminUser);
}
});
LoginHelper.logout(req, res);
res.render('default', {
title: 'Your account has been deleted',
text: 'Goodbye old friend.'
});
}
else {
res.render('default', {
title: 'Couldn\'t Delete Account',
text: 'The verification string did not match, we couldn\'t delete your account. Try again maybe?'
});
}
});
}
else {
var verifySalt = bcrypt.gen_salt_sync(10);
var verifyHash = bcrypt.encrypt_sync(req.user._id+req.user.created_at, verifySalt);
var deleteLink = siteInfo.site_url + "/user/" + req.params.id + "/remove?verify="+verifyHash;
var verificationMessage = "Hi!<br> Click to verify that you want to delete your account: <a href="\""">" + deleteLink + "</a>";
var verificationMessagePlain = "Hi! Go to this address to verify that you want to delete your account: " + deleteLink;
server.send({
text: verificationMessagePlain,
from: 'Management <' + siteInfo.site_email + '>',
to: req.user.email,
subject: 'Confirm Account Removal',
attachment:
[ {data:verificationMessage, alternative:true} ]
}, function(err, message) { console.log(err || message); })
res.render('default', {
title: 'Account Removel Request Sent',
validateUserData = function (req, callback) {
errors = [];
data = {};
if (req.param('password')) {
if (req.param('password').length < 5) {
errors.push('Password too short.');
}
else if (req.param('password') !== req.param('password_confirm')) {
errors.push('Passwords did not match.' + req.param('password' + ' ' + req.param('password_confirm')));
}
else {
var salt = bcrypt.gen_salt_sync(10);
var hash = bcrypt.encrypt_sync(req.param('password'), salt);
data.password = hash;
}
}
else if (!req.param('id')) {
errors.push('Password required.');
}
if (!req.param('username')) {
errors.push('Username required.');
}
if (!req.param('name')) {
errors.push('Name required.');
}
if (!/.*@.*\..*/.test(req.param('email'))){
errors.push('Valid email required.');
}
bootstrap: function (email, password, extra_fields) {
var salt = bcrypt.gen_salt_sync(10);
var hash = bcrypt.encrypt_sync(password, salt);
redis.hmset(req.body.email, "encrypted_password", hash, "email", email, function (err) {
console.log("Bootstrapped user authentication system");
});
}
};
function(callback)
{
var salt = bcrypt.gen_salt_sync(10);
var hash = bcrypt.encrypt_sync(password, salt);
userObj.password = hash;
client.query("UPDATE `primarywall`.`user` SET JSON = ? WHERE UserID = ?", [JSON.stringify(userObj), userId], callback);
}
],callback);
userDb.findOne({is_root:'on'}, function(error, result) {
if (error) {
log.warn('Could not determine if this is the first run. Is mongodb running?');
}
else if(!result) {
log.info('Looks like this is your first run! Hello and Welcome.');
var newPassword = '';
var newUserData = {};
newPassword = newPassword.randomString(10);
var salt = bcrypt.gen_salt_sync(10);
var newPasswordHash = bcrypt.encrypt_sync(newPassword, salt);
getNextInt('users', function(error, count) {
if (error) {
log.error('Couldn\'t create admin user id. Is mongo running? Error: ' + error);
} else {
newUserData = { "_id" : count,
"email" : "admin@example.com",
"is_admin" : 'on',
"is_root" : 'on',
"name" : "Mister Admin",
"password" : newPasswordHash,
"username" : "admin" }
newUserData.created_at = new Date();
newUserData.modified_at = new Date();
userDb.insert( newUserData, function( error, userData) {
if (error) {
setPassword: function(password) {
if (this.passwordPath) {
var salt = bcrypt.gen_salt_sync(10);
this.password = bcrypt.encrypt_sync(password, salt);
fs.writeFileSync(this.passwordPath, this.password);
}
},
getUser(req.body.email, function (user) {
if (user) {
if (user.last_request_at < (+helpers.yesterday()) || req.body.psk != user.perishable_token) {
redir();
} else if (req.body.password && req.body.password.length > 6 && req.body.password.length < 200 && req.body.password == req.body.password_confirmation) {
var salt = bcrypt.gen_salt_sync(10);
var hash = bcrypt.encrypt_sync(req.body.password, salt);
var pt = helpers.persistence_token()
user.encrypted_password = hash;
user.persistence_token = pt;
user.last_login_at = user.current_login_at;
user.last_login_ip = user.current_login_ip;
user.current_login_at = +(new Date());
user.current_login_ip = req.connection.remoteAddress;
saveUser(user, function () {
req.session.pt = pt;
res.render(__dirname+"/views/updated_password", {layout: __dirname+"/views/layout"});
}, redir);
} else {
res.render(__dirname+"/views/update_password", {
layout: __dirname+"/views/layout",