I created a Random Password Generator awhile back as well. Mine how ever has a GUI. You can find the complete program at
#!/usr/bin/env python
#----------------------------------------------------------------------
# randompass.py
# Author: Shady Tyrant
# 07/20/2009
#----------------------------------------------------------------------
import sys
import random
from GladeWindow import *
#----------------------------------------------------------------------
class randompass(GladeWindow):
#----------------------------------------------------------------------
def __init__(self):
''' '''
self.init()
#----------------------------------------------------------------------
def init(self):
filename = 'randompass.glade'
widget_list = [
'window1',
'charNumEntry',
'genButton',
'clearButton',
'passEntry',
]
handlers = [
'on_genButton_clicked',
'on_clearButton_clicked',
]
top_window = 'window1'
GladeWindow.__init__(self, filename, top_window, widget_list, handlers)
#----------------------------------------------------------------------
def on_genButton_clicked(self, *args):
# Creates tuple of chars used, 71 total
mystring = ("A","B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", \
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", \
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", \
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", \
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", "@", "#", \
"$", "%", "^", "&", "*", "_")
try:
num = int(self.widgets['charNumEntry'].get_text())
if num >= 72:
self.widgets['passEntry'].set_text('ERROR: length to large')
except:
self.widgets['passEntry'].set_text('ERROR: Failed Recieving Length Value')
# Creates random pass and prints to textbox
rPass = ''.join(random.sample(mystring, num))
self.widgets['passEntry'].set_text(rPass)
#----------------------------------------------------------------------
def on_clearButton_clicked(self, *args):
self.widgets['passEntry'].set_text('')
self.widgets['charNumEntry'].set_text('')
#----------------------------------------------------------------------
def main(argv):
w = randompass()
w.show()
gtk.main()
#----------------------------------------------------------------------
if __name__ == '__main__': main(sys.argv)