I can see two solutions for your problem.
First one is to use some library to wrap asynchronous calls. You may try node-sync or node-promise. node-sync
is better suited for what you want.
Second solution is to use bcrypt instead of crypto:
var bcrypt = require('bcrypt');
var salt = bcrypt.genSaltSync(10);
var hash = bcrypt.hashSync(password, salt);
bcrypt
is a special library for password hashing in node. It's more secure then build-in crypto module and provides some useful methods like hashSync
and compareSync
.