How to use the generate-password.generate function in generate-password

To help you get started, we’ve selected a few generate-password 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 Widen / cloudfront-auth / tests / tests.js View on Github external
res.write(codeHtml);
  }
  res.end();
});
server.listen(testConfig.port);

// Toggle ngrok auth if necessary
switch(testConfig.auth) {
  case("y"):
    // Generate password for ngrok
    var generator = require('generate-password');
    var username = generator.generate({
      length: 10,
      numbers: true
    });
    var password = generator.generate({
      length: 10,
      numbers: true
    });
    console.log(colors.red("USERNAME: ") + colors.green(username));
    console.log(colors.red("PASSWORD: ") + colors.green(password));
    ngrok.connect({
      addr: testConfig.port,
      auth: username + ':' + password    
    }, function(err, url){
      if (err) {
        console.log(err);
        exit(1);
      }
      setupRedirect(url, testConfig.lambdaFunction);
    });
    break;
github phylogeny-explorer / explorer / user-api / src / controllers / authentication.js View on Github external
return User.findOne({ $or: [{ username: req.body.username }, { email: req.body.username }], isActive: true }, (err, user) => {
      if (err) {
        return next(err);
      }

      if (!user) {
        return res.status(400).json({
          success: false,
          message: "Can't find username or email. Check the spelling. This user may not exist -- you should register.",
        });
      }

      user.passwordResetCode = generator.generate({
        length: 16,
        numbers: true,
        excludeSimilarCharacters: false,
        symbols: false,
      });

      user.passwordResetExpiry = new Date((new Date()).getTime() + (30 * 60000)); // 30 minutes expiry

      user.save((err, user) => {
        if (err) {
          console.error("User update error: Can't save password reset code.", err);
          return res.status(400).json({
            success: false,
            message: "Can't save password reset code.",
          });
        }
github notechsolution / nodeboot / server / users / models / user.server.model.js View on Github external
return new Promise(function (resolve, reject) {
    var password = '';
    var repeatingCharacters = new RegExp('(.)\\1{2,}', 'g');

    // iterate until the we have a valid passphrase
    // NOTE: Should rarely iterate more than once, but we need this to ensure no repeating characters are present
    while (password.length < 20 || repeatingCharacters.test(password)) {
      // build the random password
      password = generatePassword.generate({
        length: Math.floor(Math.random() * (20)) + 20, // randomize length between 20 and 40 characters
        numbers: true,
        symbols: false,
        uppercase: true,
        excludeSimilarCharacters: true
      });

      // check if we need to remove any repeating characters
      password = password.replace(repeatingCharacters, '');
    }

    // Send the rejection back if the passphrase fails to pass the strength test
    if (owasp.test(password).errors.length) {
      reject(new Error('An unexpected problem occured while generating the random passphrase'));
    } else {
      // resolve with the validated passphrase
github weareopensource / Node / modules / users / services / user.service.js View on Github external
exports.generateRandomPassphrase = () => {
  let password = '';
  const repeatingCharacters = new RegExp('(.)\\1{2,}', 'g');
  // iterate until the we have a valid passphrase
  // NOTE: Should rarely iterate more than once, but we need this to ensure no repeating characters are present
  while (password.length < 20 || repeatingCharacters.test(password)) {
    // build the random password
    password = generatePassword.generate({
      length: Math.floor(Math.random() * (20)) + 20, // randomize length between 20 and 40 characters
      numbers: true,
      symbols: false,
      uppercase: true,
      excludeSimilarCharacters: true,
    });

    // check if we need to remove any repeating characters
    password = password.replace(repeatingCharacters, '');
  }
  // Send the rejection back if the passphrase fails to pass the strength test
  return this.checkPassword(password);
};
github TryGhost / Ghost-CLI / extensions / mysql / index.js View on Github external
createUser(ctx, dbconfig) {
        const randomPassword = generator.generate({
            length: 20,
            numbers: true,
            symbols: true,
            strict: true
        });

        // This will be the "allowed connections from" host of the mysql user.
        // If the db connection host is something _other_ than localhost (e.g. a remote db connection)
        // we want the host to be `%` rather than the db host.
        const host = !localhostAliases.includes(dbconfig.host) ? '%' : dbconfig.host;

        let username;

        // Ensure old passwords is set to 0
        return this._query('SET old_passwords = 0;').then(() => {
            this.ui.logVerbose('MySQL: successfully disabled old_password', 'green');
github sirceljm / aws-lambda-blog / install.js View on Github external
console.log();
                            console.log("API Gateway: " + chalk.green(config.api_gateway_name) + " was created");
                            resolve(data.id);
                        }
                    });
                }
            }
        });
    });

    config.api_gateway_stage_variables.objects_table = config.table_prefix + "_objects";
    config.api_gateway_stage_variables.posts_table = config.table_prefix + "_posts";

    config.api_gateway_stage_variables.articles_bucket = config.bucket_name;

    config.api_gateway_stage_variables.signing_key = pass_generator.generate({
        length: 20,
        numbers: true,
        symbols: false,
        uppercase: true
    });

    var deployment_id = yield new Promise(function (resolve, reject) {
        var params = {
            restApiId: api_id,
            stageName: 'prod',
            cacheClusterEnabled: false,
            variables: config.api_gateway_stage_variables
        };
        apigateway.createDeployment(params, function (err, data) {
            if (err) {
                console.log(err, err.stack);
github gauravchl / secure-wallet / src / components / password-generator.jsx View on Github external
getPassword() {
    const { length, numbers, symbols, uppercase } = this.state;
    return Generator.generate({ length, numbers, symbols, uppercase });
  }
github nodemailer / mailcast / routes / users / index.js View on Github external
result.value.emailValidated = true;

        if (result.value.locale && !localeCodes.includes(result.value.locale)) {
            delete result.value.locale;
        }

        if (result.value.tz && !timezones.includes(result.value.tz)) {
            delete result.value.tz;
        }

        if (result.value.status && !statusKeys.includes(result.value.status)) {
            delete result.value.status;
        }

        result.value.password = generatePassword.generate({
            length: 14,
            uppercase: true,
            numbers: true,
            symbols: false
        });

        let user;
        try {
            user = await userModel.create(result.value);
        } catch (err) {
            return showErrors(err);
        }

        req.flash('success', 'Account created for ' + result.value.email);
        res.redirect('/users?user=' + user);
    })
github betagouv / preuve-covoiturage / api / src / auth / auth-controller.js View on Github external
User.findOne({ email }, (err, user) => {
    if (err) throw err;

    if (!user) {
      res.status(401).json({
        success: false,
        msg: `Utilisateur ${email} introuvable`,
      });
    } else {
      const password = generator.generate({ length: 10, numbers: true });
      user.set({ password });

      user.save((err2) => {
        if (err2) throw err;
        res.json({
          success: true,
          msg: 'Mot de passe modifié',
        });
      });
    }
  });
});

generate-password

Easy library for generating unique passwords.

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis

Popular generate-password functions