PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Password Generator (Python)



meckl
18.01.2008, 00:49
Password Generator


#!/usr/bin/python

#Password generater that uses type and length.

#There are 4 types to use: alphanum, alpha, alphacap, all

#d3hydr8[at]gmail[dot]com



import random, sys



def title():

print "nt d3hydr8[at]gmail[dot]com Password Gen v1.1"

print "t-----------------------------------------------n"



def passgen(choice, length):



passwd = ""



alphanum = ('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL MNOPQRSTUVWXYZ')

alpha = ('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV WXYZ')

alphacap = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ')

all = ('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV WXYZ0123456789!@#$%^&*()-_+=~`[]{}|:;"'<>,.?/')



if str(choice).lower() == "alphanum":

choice = alphanum



elif str(choice).lower() == "alpha":

choice = alpha



elif str(choice).lower() == "alphacap":

choice = alphacap



elif str(choice).lower() == "all":

choice = all



else:

print "Type doesn't matchn"

sys.exit(1)



return passwd.join(random.sample(choice, int(length)))



title()

if len(sys.argv) <= 3 or len(sys.argv) == 5:

print "nUsage: ./passgen.py <type> <length of password> <how many>"

print "t[options]"

print "t -w/-write <file> : Writes passwords to filen"

print "There are 4 types to use: alphanum, alpha, alphacap, alln"

sys.exit(1)



for arg in sys.argv[1:]:

if arg.lower() == "-w" or arg.lower() == "-write":

txt = sys.argv[int(sys.argv[1:].index(arg))+2]



if sys.argv[3].isdigit() == False:

print sys.argv[3],"must be a numbern"

sys.exit(1)

if sys.argv[2].isdigit() == False:

print sys.argv[2],"must be a numbern"

sys.exit(1)

try:

if txt:

print "[+] Writing Data:",txt

output = open(txt, "a")

except(NameError):

txt = None

pass



for x in xrange(int(sys.argv[3])):

if txt != None:

output.writelines(passgen(sys.argv[1],sys.argv[2])+"n")

else:

print "Password:",passgen(sys.argv[1],sys.argv[2])

print "n[-] Donen"

rob00n
18.01.2008, 13:35
Zeile 37 muss so sein:

all = ('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV WXYZ0123456789!@#$%^&*()-_+=~`[]{}|:;"\'<>,.?/')
Aber sonst geht alles.