Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

120 lignes
3.6 KiB

  1. #!/usr/bin/env node
  2. 'use strict';
  3. const copyPaste = require('copy-paste');
  4. const meow = require('meow');
  5. const LessPass = require('lesspass');
  6. const read = require('read');
  7. const chalk = require('chalk');
  8. const helpMessage = `
  9. Usage
  10. $ lesspass <site> <login> [masterPassword] [options]
  11. Options
  12. -l add lowercase in password
  13. -u add uppercase in password
  14. -d add digits in password
  15. -s add symbols in password
  16. --no-lowercase remove lowercase from password
  17. --no-uppercase remove uppercase from password
  18. --no-digits remove digits from password
  19. --no-symbols remove symbols from password
  20. --length, -L int (default 16)
  21. --counter, -c int (default 1)
  22. --clipboard, -C copy generated password to clipboard rather than displaying it.
  23. Need pbcopy (OSX), xclip (Linux) or clip (Windows).
  24. Examples
  25. # no symbols
  26. $ lesspass lesspass.com contact@lesspass.com password --no-symbols
  27. OlfK63bmUhqrGODR
  28. # no symbols shortcut
  29. $ lesspass lesspass.com contact@lesspass.com password -lud
  30. OlfK63bmUhqrGODR
  31. # only digits and length of 8
  32. $ lesspass lesspass.com contact@lesspass.com -d -L8
  33. master password:
  34. 75837019`;
  35. const cli = meow(helpMessage, {
  36. alias: {L: 'length', c: 'counter', C: 'clipboard'},
  37. boolean: ['l', 'u', 'd', 's', 'C', 'clipboard']
  38. });
  39. function calcPassword(site, login, masterPassword, passwordProfile) {
  40. LessPass.generatePassword(site, login, masterPassword, passwordProfile)
  41. .then(function (generatedPassword) {
  42. if (passwordProfile.clipboard) {
  43. copyPaste.copy(generatedPassword, function () {
  44. console.log("Copied to clipboard");
  45. process.exit();
  46. });
  47. } else {
  48. console.log(generatedPassword);
  49. process.exit();
  50. }
  51. });
  52. }
  53. function hasNoShortOption(options) {
  54. let hasShortOption = false;
  55. ['l', 'u', 'd', 's'].forEach(function (shortOption) {
  56. if (typeof options[shortOption] !== 'undefined' && options[shortOption]) {
  57. hasShortOption = true;
  58. }
  59. });
  60. return !hasShortOption;
  61. }
  62. function getOptionBoolean(options, optionString) {
  63. let shortOption = optionString.substring(0, 1);
  64. if (options[shortOption]) {
  65. return true;
  66. }
  67. if (typeof options[optionString] === 'undefined') {
  68. return hasNoShortOption(options);
  69. }
  70. return options[optionString]
  71. }
  72. const lowercase = getOptionBoolean(cli.flags, 'lowercase');
  73. const uppercase = getOptionBoolean(cli.flags, 'uppercase');
  74. const symbols = getOptionBoolean(cli.flags, 'symbols');
  75. const digits = getOptionBoolean(cli.flags, 'digits');
  76. const passwordProfile = {
  77. lowercase: lowercase,
  78. uppercase: uppercase,
  79. symbols: symbols,
  80. numbers: digits,
  81. clipboard: cli.flags.clipboard || false,
  82. length: cli.flags.length || 16,
  83. counter: cli.flags.counter || 1
  84. };
  85. const site = cli.input[0];
  86. const login = cli.input[1];
  87. if (typeof site === 'undefined' && typeof login === 'undefined') {
  88. console.log(chalk.red('site or login cannot be empty'));
  89. console.log('type lesspass --help');
  90. process.exit(-1);
  91. }
  92. if (cli.input.length === 3) {
  93. const masterPassword = cli.input[2];
  94. calcPassword(site, login, masterPassword, passwordProfile)
  95. } else {
  96. read({prompt: 'master password: ', silent: true}, function (er, password) {
  97. calcPassword(site, login, password, passwordProfile)
  98. });
  99. }