How to use the bcryptjs.genSaltSync function in bcryptjs

To help you get started, we’ve selected a few bcryptjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plinionaves / angular-graphcool-chat / graphcool / src / email-password / signup.ts View on Github external
const { name, email, password } = event.data;

    if (!validator.isEmail(email)) {
      return { error: 'Not a valid email' };
    }

    // check if user exists already
    const userExists: boolean = await getUser(api, email)
      .then(r => r.User !== null);
    if (userExists) {
      return { error: 'Email already in use' };
    }

    // create password hash
    const salt = bcrypt.genSaltSync(SALT_ROUNDS);
    const hash = await bcrypt.hash(password, salt);

    // create new user
    const userId = await createGraphcoolUser(api, name, email, hash);

    // generate node token for new User node
    const token = await graphcool.generateNodeToken(userId, 'User');

    return { data: { id: userId, token } };

  } catch (e) {
    console.log(e);
    return { error: 'An unexpected error occured during signup.' };
  }
};
github zhaotoday / less.js / src / app / controllers / apis / v1 / managers.js View on Github external
const passwordHash = (() => {
        // 生成 salt 的迭代次数
        const SALT_ROUNDS = 10
        // 随机生成 salt
        const salt = bcrypt.genSaltSync(SALT_ROUNDS)
        // 获取 hash 值
        return bcrypt.hashSync(password, salt)
      })()
github zbo14 / constellate / lib / crypto.js View on Github external
function generateSecret(password) {
    let secret;
    try {
        const salt = bcryptjs.genSaltSync(saltRounds);
        const hash = bcryptjs.hashSync(password, salt).slice(-53);
        secret = new Buffer(
            (atob(hash.slice(0, 22)) + atob(hash.slice(22))).slice(-32),
            'ascii'
        );
    } catch (err) {
        console.error(err);
        secret = crypto.createHash('sha256').update(password).digest();
    }
    return secret;
}
github ariabuckles / viridium / viridium.js View on Github external
read(ROUNDS_PROMPT, (error, roundsStr, isDefault) => {
            const rounds = Number(roundsStr);
            if (Number.isFinite(rounds) && rounds >= 10 && rounds <= 30) {
                const salt = bcrypt.genSaltSync(rounds);
                callback(salt);
            } else {
                console.error('Cancelled.');
            }
        });
    });
github accimeesterlin / bravesapp / vendors / modals / vendor.js View on Github external
userSchema.methods.generateHash = function (password) {

    return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null)

};
github azigler / pinwheel / src / Account.js View on Github external
_hashPassword(password) {
    const salt = bcrypt.genSaltSync(10);
    return bcrypt.hashSync(password, salt);
  }
github casual-simulation / aux / src / aux-server / server / directory / DirectoryService.ts View on Github external
async update(update: DirectoryUpdate): Promise {
        const validation = DirectoryUpdateSchema.validate(update);
        if (validation.error) {
            return {
                type: 'bad_request',
                errors: validation.error.details.map(d => ({
                    path: d.path,
                    message: d.message,
                })),
            };
        }

        let existing = await this._store.findByHash(update.key);

        if (!existing) {
            let salt = genSaltSync(10);
            let hash = hashSync(update.password, salt);
            let entry: DirectoryEntry = {
                key: update.key,
                passwordHash: hash,
                privateIpAddress: update.privateIpAddress,
                publicIpAddress: update.publicIpAddress,
                publicName: update.publicName,
                lastUpdateTime: unixTime(),
            };

            return await this._updateEntry(entry, null);
        }

        if (!compareSync(update.password, existing.passwordHash)) {
            return {
                type: 'not_authorized',
github Qlik-Branch / branch-resource-library / server / controllers / passport / reset.js View on Github external
var createSalt = function(password) {
  return bCrypt.hashSync(password, bCrypt.genSaltSync(10), null)
}
github mjhea0 / node-docker-api / services / users / src / auth / _helpers.js View on Github external
function createUser(req) {
  const salt = bcrypt.genSaltSync();
  const hash = bcrypt.hashSync(req.body.password, salt);
  return knex('users')
  .insert({
    username: req.body.username,
    password: hash,
  })
  .returning('*');
}
github PacktPublishing / Building-Enterprise-JavaScript-Applications / Chapter09 / hobnob / spec / cucumber / steps / auth.js View on Github external
async function createUser () {
  const user = {};
  user.email = chance.email();
  user.password = crypto.randomBytes(32).toString('hex');
  user.salt = bcrypt.genSaltSync(10);
  user.digest = bcrypt.hashSync(user.password, user.salt);
  const result = await client.index({
    index: process.env.ELASTICSEARCH_INDEX_TEST,
    type: 'user',
    body: {
      email: user.email,
      digest: user.digest
    },
    refresh: true
  });
  user.id = result._id;
  return user;
}

bcryptjs

Optimized bcrypt in plain JavaScript with zero dependencies. Compatible to 'bcrypt'.

MIT
Latest version published 7 years ago

Package Health Score

73 / 100
Full package analysis