Permalink
Browse files

added test cases to prove bug in pw length > 19

  • Loading branch information...
1 parent 20fe83c commit 1d91ea4db16f81457be6e165122c39415528c6a3 @richbeales committed May 21, 2012
Showing with 82 additions and 34 deletions.
  1. +17 −18 passwordmaker.py
  2. +46 −16 pwmlib.py
  3. +19 −0 testpwmlib.py
View
@@ -120,15 +120,22 @@ def createWidgets(self):
self.passwd_label.grid(row=11,column=0)
self.passwd_text.grid(row=11,column=1,sticky="nsew")
+ def getsettings(self):
+ settings = PWM_Settings()
+ settings.URL = self.url_text.get()
+ settings.Algorithm = self.alg.get()
+ settings.Username = self.user_text.get()
+ settings.Modifier = self.mod_text.get()
+ settings.Length = int(self.len_spinner.get())
+ settings.CharacterSet = self.charset_text.get()
+ settings.Prefix = self.pfx_text.get()
+ settings.Suffix = self.sfx_text.get()
+ settings.MasterPass = self.mpw_text.get()
+ return settings
+
def save(self):
- self.settings.URL = self.url_text.get()
- self.settings.Algorithm = self.alg.get()
- self.settings.Username = self.user_text.get()
- self.settings.Modifier = self.mod_text.get()
- self.settings.Length = self.len_spinner.get()
- self.settings.CharacterSet = self.charset_text.get()
- self.settings.Prefix = self.pfx_text.get()
- self.settings.Suffix = self.sfx_text.get()
+ self.settings = self.getsettings()
+ self.settings.MasterPass = '' # blank this out when saving for now
self.settings.save()
def load(self):
@@ -138,16 +145,8 @@ def load(self):
def generate(self):
self.generate_button.flash()
try:
- pw = self.PWmaker.generatepassword(self.alg.get(),
- self.mpw_text.get(),
- self.url_text.get() + self.user_text.get() + self.mod_text.get(),
- self.settings.UseLeet,
- self.settings.LeetLvl - 1,
- int(self.len_spinner.get()),
- self.charset_text.get(),
- self.pfx_text.get(),
- self.sfx_text.get(),
- )
+ print self.getsettings()
+ pw = self.PWmaker.generatepasswordfrom(self.getsettings())
except PWM_Error, e:
pw = str(e)
current_passwd = self.passwd_text.get()
View
@@ -50,6 +50,7 @@ class PWM:
"""
Main PasswordMaker class used for generating passwords
"""
+ FULL_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";\'<>?,./"
def __init__(self):
self.valid_algs = self.getValidAlgorithms()
@@ -67,6 +68,18 @@ def getValidAlgorithms(self):
pass
return valid_algs
+ def generatepasswordfrom(self,settings):
+ return self.generatepassword(settings.Algorithm,
+ settings.MasterPass,
+ settings.URL + settings.Username + settings.Modifier,
+ settings.UseLeet,
+ settings.LeetLvl,
+ settings.Length,
+ settings.CharacterSet,
+ settings.Prefix,
+ settings.Suffix)
+
+ # L33t not used here
def generatepassword(self,hashAlgorithm, key, data, whereToUseL33t, l33tLevel, passwordLength, charset, prefix="", suffix=""):
# Never *ever, ever* allow the charset's length<2 else
# the hash algorithms will run indefinitely
@@ -254,26 +267,43 @@ def any_hmac_rmd160(self, k, d, e, t):
class PWM_Settings:
def __init__(self):
- self.URL = ""
- #self.MasterPass = "" # don't really want to save this
- self.Algorithm = "md5"
- self.Username = ""
- self.Modifier = ""
- self.Length = 8
- self.CharacterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";\'<>?,./"
- self.Prefix = ""
- self.Suffix = ""
- self.UseLeet = False
- self.LeetLvl = 0
+ self.URL = ""
+ self.MasterPass = "" # don't really want to save this
+ self.Algorithm = "md5"
+ self.Username = ""
+ self.Modifier = ""
+ self.Length = 8
+ self.CharacterSet = PWM().FULL_CHARSET
+ self.Prefix = ""
+ self.Suffix = ""
+ self.UseLeet = False
+ self.LeetLvl = 1
+
+ def __str__(self):
+ return "URL=%s\nPWD=%s\nAlg=%s\nUsr=%s\nMod=%s\nLen=%s\nChr=%s\nPfx=%s\nSfx=%s\nL3t=%s\nLvl=%s\n" % (
+ self.URL,
+ self.MasterPass,
+ self.Algorithm,
+ self.Username,
+ self.Modifier,
+ self.Length,
+ self.CharacterSet,
+ self.Prefix,
+ self.Suffix,
+ self.UseLeet,
+ self.LeetLvl,
+ )
+
def load(self):
import os
if os.path.exists('pwm.settings'):
- import pickle
- f = open('pwm.settings','rb')
- settings = pickle.load(f)
- f.close()
- return settings
+ import pickle
+ f = open('pwm.settings','rb')
+ settings = pickle.load(f)
+ f.close()
+ return settings
+ return PWM_Settings()
def save(self):
import pickle
View
@@ -0,0 +1,19 @@
+#! /usr/env/python
+
+from pwmlib import *
+import unittest
+
+class PWTest(unittest.TestCase):
+ def setUp(self):
+ self.pw = PWM()
+
+ def test_generatepassword_19chars(self):
+ res = self.pw.generatepassword('md5','asdf','passwordmaker.org'+''+'',False,1,19,self.pw.FULL_CHARSET,'','')
+ self.assertEqual(res,'FRRHm)k+UyQiY~%Dj;h')
+
+ def test_generatepassword_20chars(self):
+ res = self.pw.generatepassword('md5','asdf','passwordmaker.org'+''+'',False,1,20,self.pw.FULL_CHARSET,'','')
+ self.assertEqual(res,'FRRHm)k+UyQiY~%Dj;h*')
+
+if __name__ == '__main__':
+ unittest.main()

0 comments on commit 1d91ea4

Please sign in to comment.