How to use password-hash - 10 common examples

To help you get started, we’ve selected a few password-hash 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 DenysVuika / collab.js / collabjs.web.api.js View on Github external
app.post('/api/account/register', function (req, res) {

      if (!config.server.allowUserRegistration) {
        res.status(400).send('Registration is not allowed with current configuration.');
        return;
      }

      var body = req.body;
      // TODO: introduce better validation
      if (body.account && body.name && body.email && body.password) {
        var hashedPassword = passwordHash.generate(body.password);

        var user = {
          account: body.account,
          name: body.name,
          password: hashedPassword,
          email: body.email
        };

        repository.createAccount(user, function (err, result) {
          if (err) { res.status(400).send(err); }
          else {
            req.login({ id: result.id, username: user.account, password: hashedPassword }, function (err) {
              if (err) { res.status(400).send('Error authenticating user.'); }
              else {
                // notify running modules on user registration
                context.emit(context.events.userRegistered, { id: result.id, account: user.account });
github DenysVuika / collab.js / collabjs.admin.api.js View on Github external
.post(function (req, res) {
        var user = {
          account: req.body.account,
          name: req.body.name,
          password: passwordHash.generate(req.body.password),
          email: req.body.email
        };

        repository.createAccount(user, function (err, result) {
          if (err) { res.send(400, err); }
          else {
            // notify running modules on user registration
            context.emit(context.events.userRegistered, { id: result.id, account: user.account });
            res.send(200);
          }
        });
      });
github IBM / real-time-payments / server.js View on Github external
function createLocalUser(username, password, fname, lname, fn) {
	var unique = makeUniqueUsername(username);
	var p = passwordHash.generate(password);
	console.log('creating local user ' + username + '(' + unique + ')');
	createDDACustomer(username, p, unique, fname, lname, function(err, ddaUser) {
		var prefix = generateAccountNumberPrefix(username);
		// create and fund a couple of accounts
		createDDAAccount(unique, 'mySavings', prefix + 2, 'S', 10000, function(err, account) {
			createDDAAccount(unique, 'myChecking', prefix + 1, 'C', 10000, function(err, account) {
				return fn(err, ddaUser);
			});
		});
	});
}
github ZencashOfficial / arizen / app / main.js View on Github external
function generateNewAddress(count, password) {
    let i;
    let seedHex = passwordHash.generate(password, {
        "algorithm": "sha512",
        "saltLength": 32
    }).split("$")[3];

    // chains
    let hdNode = bitcoin.HDNode.fromSeedHex(seedHex);
    let chain = new bip32utils.Chain(hdNode);

    for (i = 0; i < count; i += 1) {
        chain.next();
    }

    // Get private keys from them - return privateKeys
    return chain.getAll().map(function (x) {
        return chain.derive(x).keyPair.toWIF();
    });
github ZencashOfficial / arizen / app / main.js View on Github external
function generateNewAddress(count, password) {
    let i;
    let seedHex = passwordHash.generate(password, {
        "algorithm": "sha512",
        "saltLength": 32
    }).split("$")[3];

    // chains
    let hdNode = bitcoin.HDNode.fromSeedHex(seedHex);
    let chain = new bip32utils.Chain(hdNode);

    for (i = 0; i < count; i += 1) {
        chain.next();
    }

    // Get private keys from them - return privateKeys
    return chain.getAll().map(function (x) {
        return chain.derive(x).keyPair.toWIF();
    });
github cs-education / classTranscribe / archive / router / routes / changePassword.js View on Github external
// Check that the two passwords are the same
    if (password != re_password) {
        var error = "Passwords are not the same";
        perror(error);
        response.send({ message: error, html: '' });
    } else {
      // Check if password follows pattern schema
      var valid_pattern = schema.validate(password)
      if (valid_pattern != true) {
        var error = "Password must have at least 8 character, an uppercase letter, a lowercase leter, a digit, and no spaces.";
        perror(error);
        response.send({ message: error, html: '' });
      } else {
        // Salt and hash password before putting into redis database
        var hashedPassword = passwordHash.generate(password);

        db.setUserPassword(hashedPassword, userInfo.mailId).then(() => {
          response.send({ message: 'success', html: '../dashboard' })
        }).catch(err => perror(err)); /* db.setUserPassword() */
      }
    }
  } else {
    response.send({ message: 'Not Authenticated', html: '../login' })
  }
});
github cs-education / classTranscribe / router / routes / signup.js View on Github external
crypto.randomBytes(48, function (err, buffer) {
                  var token = buffer.toString('hex');
                  var host = request.get('host');
                  var link = 'https://' + host + '/verify?email=' + email + '&id=' + token;

                  // Salt and hash password before putting into redis database
                  var hashedPassword = passwordHash.generate(password);

                  // Send email to verify .edu account
                  var mailOptions = {
                    from: 'ClassTranscribe Team <' + mailID + '>', // ClassTranscribe no-reply email
                    to: email, // receiver who signed up for ClassTranscribe
                    subject: 'Welcome to ClassTranscribe', // subject line of the email
                    html: 'Hi ' + first_name + ' ' + last_name + ', <br><br> Thanks for registering at ClassTranscribe. Please verify your email by clicking this <a href="+ link +">link</a>. <br><br> Thanks! <br> ClassTranscribe Team',
                  };

                  var userInfo = {
                    mailId : email,
                    firstName : first_name,
                    lastName : last_name,
                    password : hashedPassword,
                    passwordToken : '',
                    university : getUniversity(email),
github lucybot / jammin / test / petstore-server.js View on Github external
API.User.post('/users', function(req, res, next) {
  req.jammin.document.password_hash = Hash.generate(req.body.password);
  next();
});
github DenysVuika / collab.js / data / providers / deprecated / collabjs.data.mssql.js View on Github external
self.getAccountById(userId, function (err, result) {
        if (err) {
          console.log(err);
          callback(err, result);
        } else {
          var hashedPassword = passwordHash.generate(password)
            , command = 'UPDATE users SET password = ? WHERE id = ?'
            , params = [hashedPassword, userId];
          sql.query(self.connection, command, params, function (err, result) {
            if (err) {
              console.log(err);
              callback(err, result);
            } else {
              callback(null, hashedPassword);
            }
          });
        }
      });
    }
github thejh / node-forum / user.js View on Github external
function createUser(name, password, doc, cb) {
  if (!USERNAME.test(name)) return cb(new Error('invalid username (allowed: '+USERNAME+')'))
  if (password.length &lt; 5) return cb(new Error("I don't want to force you to use a super-long password, but "+password.length+" chars is way too short"))
  var docname = 'user:'+name
  doc.name = name
  doc.password = pwhash.generate(password, {algorithm: 'sha512'})
  forum.db.store(docname, doc, function(err) {
    if (err) return cb(err)
    var loginProof = sign('validloginas:'+name)
    cb(null, {proof: loginProof})
  })
}

password-hash

Password hashing and verification for node.js

MIT
Latest version published 10 years ago

Package Health Score

50 / 100
Full package analysis

Popular password-hash functions