shaneMangudi / bcrypt-nodejs

Native implementation of bcrypt for NodeJS
Other
574 stars 69 forks source link

hashSync broken, "TypeError: salt.charAt is not a function" #80

Open neilbalch opened 7 years ago

neilbalch commented 7 years ago

On the bcrypt-nodejs demo, I am not able to hash a password with the syntax provided:

var bcryptNodejs = require("bcrypt-nodejs")

var hash = bcryptNodejs.hashSync("bacon", 10);
console.log(hash);

The error:

TypeError: salt.charAt is not a function

is given. Any thoughts on when this can be fixed?

robertklep commented 6 years ago

@neilbalch pass a salt, not a number.

var bcryptNodejs = require("bcrypt-nodejs")

var salt = bcryptNodejs.genSaltSync(10);
var hash = bcryptNodejs.hashSync("bacon", salt);
console.log(hash);
Piket564 commented 5 years ago

What about

collection.find({}).toArray((err,data) => {
            console.log('\x1b[36m%s\x1b[34m', 'Getting... data.');
            async.forEach(data, (item,callback) => {
                let regex = new RegExp('^\$2[ayb]\$.{56}$');
                /*
                ^\$2[ayb]\$.{56}$
                */
                let salt = bCrypt.genSaltSync(128);
                if(!regex.test(item.pwd)){
                    item.pwd = bCrypt.hashSync(item.pwd,salt) || '';}
                    console.log(item.pwd+"\n");
            },(err) => {
              //callback
            });
            client.close();
        })