Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
set(val) {
// 加密
const salt = bcrypt.genSaltSync(10);
// 生成加密密码
const psw = bcrypt.hashSync(val, salt);
this.setDataValue("password", psw);
},
allowNull: false,
CreateUser: async (resolve, root, args, context, info) => {
args.password = await bcrypt.hashSync(args.password, 10)
const result = await resolve(root, args, context, info)
result.password = '*****'
return result
}
},
export async function insertAuthor(models) {
return models.Author.bulkCreate([
{
fname: "John",
lname: "Dave",
email: "demo@demo.com",
password: bcrypt.hashSync("demo", 12),
social: JSON.stringify({
twitter: "https://twitter.com",
facebook: "https://facebook.com",
github: "https://github.com",
instagram: "https://instagram.com",
}),
roleId: 1,
bio:
"Provident quis sed perferendis sed. Sed quo nam eum. Est quos beatae magnam ipsa ut cupiditate nostrum officiis. Vel hic sit voluptatem. Minus minima quis omnis.",
avatar: "/admin/images/avatar.png",
},
{
fname: "Jim",
lname: "Parker",
email: "author@letterpad.app",
password: bcrypt.hashSync("demo", 12),
set(val) {
const salt = bcryptjs.genSaltSync(10)
const safePwd = bcryptjs.hashSync(val, salt)
this.setDataValue('password', safePwd)
}
},
var encryptPassword = function (password) {
var salt = bcrypt.genSaltSync(10);
return bcrypt.hashSync(password, salt);
};
function hashPassword(password: string): string {
if (!password) {
return null;
}
return Bcrypt.hashSync(password, Bcrypt.genSaltSync(8));
}
this.redisClient.incr("teams:count", (incrError, teamId) => {
const token = crypto.randomBytes(20).toString("hex");
this.redisClient.hmset(`team:${teamId}`, {
name: request.body.name,
password: bcrypt.hashSync(request.body.password),
token,
}, () => {
this.redisClient.hset("name.team.mapping", request.body.name, teamId.toString(), () => {
this.redisClient.hset("token.teamname.mapping", token, request.body.name, () => {
return response.json({
status: "ok",
});
});
});
});
});
}
static bcryptedPasswordSync(password: string): string {
const salt = bcrypt.genSaltSync(10);
return bcrypt.hashSync(password, salt);
}
.then(userId =>
redis.multi([
['hsetnx', 'emails', userData.email, userId],
['hsetnx', `user:${userId}`, 'id', userId],
['hsetnx', `user:${userId}`, 'username', userData.username],
['hsetnx', `user:${userId}`, 'email', userData.email],
['hsetnx', `user:${userId}`, 'password', bcrypt.hashSync(userData.password, 10)]
]).exec()
)
add: async (message) => {
let user;
try {
user = JSON.parse(message.content.toString());
const hashedPassword = bcrypt.hashSync(user.password, 8);
await Auth.create({
role: user.role,
emailAddress: user.emailAddress,
password: hashedPassword,
});
logger.info(`user auth record created - ${user.emailAddress}`);
} catch (err) {
logger.error(`Error creating auth record for user ${user.emailAddress} : ${err}`);
}
},
};