passgen.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. '''DERFACT-passgen -- Command line password generator
  2. Copyright (C) 2022 DERFACT Corporation,
  3. DERFACT-passgen is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. DERFACT-passgen is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. '''
  14. import sys
  15. import random
  16. numbers = '1234567890'
  17. letters_l = 'abcdefghijklmnopqrstuvwxyz'
  18. letters_u = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  19. symbols = '!#$%&()*+./:;=>?@[\]^`{|}~\'_-'
  20. arg = sys.argv
  21. password_symbols = letters_l
  22. def passgen(password_symbols, password_len = 12, count = 10):
  23. for c in range(count):
  24. result = ''
  25. for i in range(password_len):
  26. r = random.randint(0, len(password_symbols) - 1)
  27. result += password_symbols[r]
  28. print(result)
  29. def arg_nums(arg):
  30. password_len = 12
  31. count = 10
  32. if arg[0].isnumeric():
  33. password_len = int(arg[0])
  34. if len(arg) > 1:
  35. if arg[1].isnumeric():
  36. count = int(arg[1])
  37. passgen(password_symbols, password_len, count)
  38. if len(arg) > 1:
  39. arg.pop(0)
  40. if '-' in arg[0]:
  41. if 'n' in arg[0]:
  42. password_symbols += numbers
  43. if 'u' in arg[0]:
  44. password_symbols += letters_u
  45. if 's' in arg[0]:
  46. password_symbols += symbols
  47. if len(arg) > 1:
  48. arg.pop(0)
  49. arg_nums(arg)
  50. else:
  51. passgen(password_symbols)
  52. else:
  53. password_symbols += letters_u + numbers
  54. arg_nums(arg)
  55. else:
  56. password_symbols += letters_u + numbers
  57. passgen(password_symbols)