Python_Prog

TSquish | Password Generator

Feb 24th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. #!/usr/bin/python
  2. import sys
  3. from random import choice
  4.  
  5. def main():
  6.     if sys.argv[1] == "-h":
  7.         exit("Usage: $ %s length amount\nEx: $ %s 5 4 will print 4 passwords all 5 characters in length" % (sys.argv[0], sys.argv[0]))
  8.     try:
  9.         len_pass = int(sys.argv[1])
  10.     except IndexError:
  11.         len_pass = 5
  12.     try:
  13.         amount_pass = int(sys.argv[2])
  14.     except IndexError:
  15.         amount_pass = 1
  16.    
  17.     passwords = [] 
  18.     for i in range(amount_pass):
  19.         passwords.append(make_pass(len_pass))
  20.    
  21.     for words in  passwords:
  22.         print words
  23.  
  24. def rand_char():
  25.     chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'l', 'm', 'n',
  26.              'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',]
  27.  
  28.     return choice(chars)
  29.  
  30. def make_pass(length):
  31.     password = ""
  32.     for i in range(length):
  33.         password += rand_char()
  34.     return password
  35.  
  36.  
  37. if __name__ == "__main__":
  38.     main()
Advertisement
Add Comment
Please, Sign In to add comment