Guest User

Untitled

a guest
Nov 18th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # author: Brandon W Maister
  4. # This file is in the public domain
  5.  
  6. """Create passwords using random words
  7.  
  8. Long passwords are better than short, a long (20+ char) password made of
  9. whole words is better than a short one, unless the attacker knows that you're
  10. using whole words.
  11.  
  12. This is good enough for me.
  13. """
  14.  
  15. import sys
  16. try:
  17. from random import SystemRandom
  18. random = SystemRandom()
  19. except ImportError:
  20. print 'weak random numbers'
  21. import random
  22.  
  23. def makepass(min_len=20):
  24. with open('/usr/share/dict/words') as fh:
  25. words = fh.readlines()
  26.  
  27. password = ''
  28. while len(password) < min_len:
  29. password += random.choice(words).lower().strip() + ' '
  30.  
  31. return password.strip()
  32.  
  33. if __name__ == '__main__':
  34. if len(sys.argv) > 1:
  35. try:
  36. print makepass(int(sys.argv[1]))
  37. except ValueError:
  38. print "Only argument is the minimum length for the password"
  39. else:
  40. print makepass()
Add Comment
Please, Sign In to add comment