How to use the keytar.addPassword function in keytar

To help you get started, we’ve selected a few keytar 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 henryboldi / felony / app / components / composer / ComposerAliasForm.js View on Github external
}

    const notification = {
      title: 'Keys Done Generating',
      body: 'Copy your public key by clicking the icon to the right of your name.',
    }

    this.props.toggleGeneratingKey()
    this.setState({ submitted: true })
    await this.props.addKey({ id: 999, name, privateKeyArmored: 'generating' })
    const key = await generateKey({ name, email }, passphrase)
    key.avatar = 9
    key.id = 999

    new Notification(notification.title, notification) // eslint-disable-line no-new
    keytar.addPassword('felony', `${ name } <${ email }>`, passphrase)
    await this.props.addKey(key)
    this.props.toggleGeneratingKey()
  }
github brave / browser-laptop / app / index.js View on Github external
// Previously the master key was binary encoded, which caused compatibility
  // issues with various keyrings. In 0.8.3, switch to hex encoding for storage.
  const oldAccountName = 'login master key'
  const accountName = 'login master key v2'
  let oldMasterKey = keytar.getPassword(appName, oldAccountName)
  let masterKey = keytar.getPassword(appName, accountName)

  let success = false

  if (masterKey === null) {
    if (typeof oldMasterKey === 'string') {
      // The user made a v1 (binary) key. Try converting it to hex if it
      // appears to be 32 bytes.
      let oldBuffer = new Buffer(oldMasterKey, 'binary')
      if (oldBuffer.length === 32) {
        success = keytar.addPassword(appName, accountName, oldBuffer.toString('hex'))
      }
    }

    // Either the user denied access or no master key has ever been created.
    // We can't tell the difference so try making a new master key.
    success = success || keytar.addPassword(appName, accountName, CryptoUtil.getRandomBytes(32).toString('hex'))

    if (success) {
      // A key should have been created
      masterKey = keytar.getPassword(appName, accountName)
    }
  }

  if (typeof masterKey === 'string') {
    // Convert from hex to binary
    return (new Buffer(masterKey, 'hex')).toString('binary')
github brave / browser-laptop / app / index.js View on Github external
let success = false

  if (masterKey === null) {
    if (typeof oldMasterKey === 'string') {
      // The user made a v1 (binary) key. Try converting it to hex if it
      // appears to be 32 bytes.
      let oldBuffer = new Buffer(oldMasterKey, 'binary')
      if (oldBuffer.length === 32) {
        success = keytar.addPassword(appName, accountName, oldBuffer.toString('hex'))
      }
    }

    // Either the user denied access or no master key has ever been created.
    // We can't tell the difference so try making a new master key.
    success = success || keytar.addPassword(appName, accountName, CryptoUtil.getRandomBytes(32).toString('hex'))

    if (success) {
      // A key should have been created
      masterKey = keytar.getPassword(appName, accountName)
    }
  }

  if (typeof masterKey === 'string') {
    // Convert from hex to binary
    return (new Buffer(masterKey, 'hex')).toString('binary')
  } else {
    throttleKeytar = true
    setTimeout(() => {
      throttleKeytar = false
    }, 1000 * 60 * 60 * 24)
    return null
github boennemann / get-npm-token / cli.js View on Github external
getToken(answers.registry, answers.username, answers.email, answers.password || password, function (err, token) {
      if (err) {
        console.error(err)
        process.exit(1)
      }

      console.log(token)
      if (keytar && !password && answers.password) keytar.addPassword('npm-get-token', answers.username, answers.password)
      conf.set('username', answers.username, 'user')
      conf.set('email', answers.email, 'user')
      conf.save('user')
    })
  })
github Pouja / jira-terminal / src / First.js View on Github external
}], function(answers) {
        keytar.addPassword('jira-terminal', answers.username, answers.password);

        delete answers.password;

        _.assign(config, answers);

        console.log('Writing the configuration file to ' + configPath);
        fs.mkdirSync(basePath);
        fs.writeFileSync(configPath, JSON.stringify(config), 'utf8');

        console.log('Starting the app.');
        cb();
    });
};
github cplusplus / LEWG / scripts / isocppWiki.js View on Github external
}).then(function(password) {
        if (keytar.addPassword('wiki.edg.com', username, password)) {
          return password;
        } else {
          throw new Error('Could not add password for ' + username + '@wiki.edg.com');
        }
      });
    } else {
github DFurnes / hey / src / configure.js View on Github external
return (options) => {
      const service = options.url.hostname;
      let password = keytar.getPassword(service, username);

      if (!password) {
        password = prompt(`Enter ${chalk.bold(username)}'s password for ${chalk.bold(service)}: `, { secure: true });
        keytar.addPassword(service, username, password);
      }

      return { username, password };
    }
  },
github cheshire137 / gh-notifications-snoozer / src / models / GitHubAuth.js View on Github external
static setToken(token) {
    if (this.isAuthenticated()) {
      this.deleteToken()
    }
    keytar.addPassword(SERVICE, ACCOUNT, token)
    if (isTest) {
      storage.set(KEY, token)
    }
  }

keytar

Bindings to native Mac/Linux/Windows password APIs

MIT
Latest version published 3 years ago

Package Health Score

58 / 100
Full package analysis