Skip to content

Commit 7ae4d4e

Browse files
committed
initial add from svn
1 parent 9a35279 commit 7ae4d4e

File tree

2 files changed

+479
-0
lines changed

2 files changed

+479
-0
lines changed

passwordmaker.py

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
"""
4+
PasswordMaker - Creates and manages passwords
5+
Copyright (C) 2005 Eric H. Jung and LeahScape, Inc.
6+
http://passwordmaker.org/
7+
8+
9+
This library is free software; you can redistribute it and/or modify it
10+
under the terms of the GNU Lesser General Public License as published by
11+
the Free Software Foundation; either version 2.1 of the License, or (at
12+
your option) any later version.
13+
14+
This library is distributed in the hope that it will be useful, but WITHOUT
15+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17+
for more details.
18+
19+
You should have received a copy of the GNU Lesser General Public License
20+
along with this library; if not, write to the Free Software Foundation,
21+
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22+
23+
Written by Miquel Burns and Eric H. Jung
24+
25+
PHP version written by Pedro Gimeno Fortea
26+
<http://www.formauri.es/personal/pgimeno/>
27+
and updated by Miquel Matthew 'Fire' Burns
28+
29+
Ported to Python by Aurelien Bompard
30+
<http://aurelien.bompard.org>
31+
Updated by Richard Beales
32+
33+
34+
This version should work with python > 2.3. The pycrypto module enables
35+
additional algorithms.
36+
37+
Can be used both on the command-line and with a GUI based on TKinter
38+
"""
39+
from pwmlib import *
40+
41+
def gui():
42+
import Tkinter
43+
class Application(Tkinter.Frame):
44+
def __init__(self, master=None):
45+
Tkinter.Frame.__init__(self, master)
46+
self.grid()
47+
self.settings = PWM_Settings()
48+
self.createWidgets()
49+
def createWidgets(self):
50+
settings = self.settings
51+
# Create the widgets
52+
self.url_label = Tkinter.Label(self, justify="left", text="URL")
53+
self.url_text = Tkinter.Entry(self)
54+
self.url_text.insert(0, settings.URL)
55+
self.mpw_label = Tkinter.Label(self, justify="left", text="Master")
56+
self.mpw_text = Tkinter.Entry(self, show="*")
57+
self.mpw_text.insert(0, "")
58+
self.alg_label = Tkinter.Label(self, justify="left", text="Algorithm")
59+
self.alg_text = Tkinter.Entry(self)
60+
self.alg_text.insert(0, settings.Algorithm)
61+
self.user_label = Tkinter.Label(self, justify="left", text="Username")
62+
self.user_text = Tkinter.Entry(self)
63+
self.user_text.insert(0, settings.Username)
64+
self.mod_label = Tkinter.Label(self, justify="left", text="Modifier")
65+
self.mod_text = Tkinter.Entry(self)
66+
self.mod_text.insert(0, settings.Modifier)
67+
self.len_label = Tkinter.Label(self, justify="left", text="Length")
68+
self.len_text = Tkinter.Entry(self)
69+
self.len_text.insert(0, str(settings.Length))
70+
self.charset_label = Tkinter.Label(self, justify="left", text="Characters")
71+
self.charset_text = Tkinter.Entry(self)
72+
self.charset_text.insert(0, settings.CharacterSet)
73+
self.pfx_label = Tkinter.Label(self, justify="left", text="Prefix")
74+
self.pfx_text = Tkinter.Entry(self)
75+
self.pfx_text.insert(0, settings.Prefix)
76+
self.sfx_label = Tkinter.Label(self, justify="left", text="Suffix")
77+
self.sfx_text = Tkinter.Entry(self)
78+
self.sfx_text.insert(0, settings.Suffix)
79+
self.generate_button = Tkinter.Button (self, text="Generate", command=self.generate)
80+
self.load_button = Tkinter.Button (self, text="Load", command=self.load)
81+
self.save_button = Tkinter.Button (self, text="Save", command=self.save)
82+
self.passwd_label = Tkinter.Label(self, justify="left", text="Password")
83+
self.passwd_text = Tkinter.Entry(self, fg="blue")
84+
# Place on the grid
85+
self.url_label.grid(row=0,column=0)
86+
self.url_text.grid(row=0,column=1)
87+
self.mpw_label.grid(row=1,column=0)
88+
self.mpw_text.grid(row=1,column=1)
89+
self.alg_label.grid(row=2,column=0)
90+
self.alg_text.grid(row=2,column=1)
91+
self.user_label.grid(row=3,column=0)
92+
self.user_text.grid(row=3,column=1)
93+
self.mod_label.grid(row=4,column=0)
94+
self.mod_text.grid(row=4,column=1)
95+
self.len_label.grid(row=5,column=0)
96+
self.len_text.grid(row=5,column=1)
97+
self.charset_label.grid(row=6,column=0)
98+
self.charset_text.grid(row=6,column=1)
99+
self.pfx_label.grid(row=7,column=0)
100+
self.pfx_text.grid(row=7,column=1)
101+
self.sfx_label.grid(row=8,column=0)
102+
self.sfx_text.grid(row=8,column=1)
103+
self.generate_button.grid(row=9,column=0,columnspan=2,pady=5)
104+
self.load_button.grid(row=10,column=0,columnspan=1,pady=5)
105+
self.save_button.grid(row=10,column=1,columnspan=1,pady=5)
106+
self.passwd_label.grid(row=11,column=0)
107+
self.passwd_text.grid(row=11,column=1,sticky="nsew")
108+
109+
def save(self):
110+
self.settings.URL = self.url_text.get()
111+
self.settings.Algorithm = self.alg_text.get()
112+
self.settings.Username = self.user_text.get()
113+
self.settings.Modifier = self.mod_text.get()
114+
self.settings.Length = self.len_text.get()
115+
self.settings.CharacterSet = self.charset_text.get()
116+
self.settings.Prefix = self.pfx_text.get()
117+
self.settings.Suffix = self.sfx_text.get()
118+
self.settings.save()
119+
120+
def load(self):
121+
self.settings = self.settings.load()
122+
self.createWidgets()
123+
124+
def generate(self):
125+
self.generate_button.flash()
126+
try:
127+
PWmaker = PWM()
128+
pw = PWmaker.generatepassword(self.alg_text.get(),
129+
self.mpw_text.get(),
130+
self.url_text.get() + self.user_text.get() + self.mod_text.get(),
131+
self.settings.UseLeet,
132+
self.settings.LeetLvl - 1,
133+
int(self.len_text.get()),
134+
self.charset_text.get(),
135+
self.pfx_text.get(),
136+
self.sfx_text.get(),
137+
)
138+
except PWM_Error, e:
139+
pw = str(e)
140+
current_passwd = self.passwd_text.get()
141+
if len(current_passwd) > 0:
142+
self.passwd_text.delete(0,len(current_passwd))
143+
self.passwd_text.insert(0,pw)
144+
app = Application()
145+
app.master.title("PasswordMaker")
146+
app.mainloop()
147+
148+
149+
def cmd():
150+
usage = "Usage: %prog [options]"
151+
settings = PWM_Settings()
152+
settings.load()
153+
parser = optparse.OptionParser(usage=usage)
154+
parser.add_option("-a", "--alg", dest="alg", default=settings.Algorithm, help="Hash algorithm [hmac-] md4/md5/sha1/sha256/rmd160 [_v6] (default " + settings.Algorithm + ")")
155+
parser.add_option("-m", "--mpw", dest="mpw", help="Master password (default: ask)", default="")
156+
parser.add_option("-r", "--url", dest="url", help="URL (default blank)", default=settings.URL)
157+
parser.add_option("-u", "--user", dest="user", help="Username (default blank)", default=settings.Username)
158+
parser.add_option("-d", "--modifier", dest="mod", help="Password modifier (default blank)", default=settings.Modifier)
159+
parser.add_option("-g", "--length", dest="len", help="Password length (default 8)", default=settings.Length, type="int")
160+
parser.add_option("-c", "--charset", dest="charset", help="Characters to use in password (default [A-Za-z0-9])", default=settings.CharacterSet)
161+
parser.add_option("-p", "--prefix", dest="pfx", help="Password prefix (default blank)", default=settings.Prefix)
162+
parser.add_option("-s", "--suffix", dest="sfx", help="Password suffix (default blank)", default=settings.Suffix)
163+
(options, args) = parser.parse_args()
164+
if options.mpw == "":
165+
import getpass
166+
options.mpw = getpass.getpass("Master password: ")
167+
# we don't support leet yet
168+
leet = None
169+
leetlevel = 0
170+
try:
171+
PWmaker = PWM()
172+
print PWmaker.generatepassword(options.alg,
173+
options.mpw,
174+
options.url + options.user + options.mod,
175+
leet,
176+
leetlevel - 1,
177+
options.len,
178+
options.charset,
179+
options.pfx,
180+
options.sfx,
181+
)
182+
except PWM_Error, e:
183+
print e
184+
sys.exit(1)
185+
186+
187+
# Main
188+
if __name__ == "__main__":
189+
if len(sys.argv) == 1:
190+
gui()
191+
else:
192+
cmd()
193+
194+
195+

0 commit comments

Comments
 (0)