Commits

Erik Grinaker committed 38bdd83

more thorough password strength checker

Comments (0)

Files changed (3)

 
 	* properly handle datahandler.DataError
 
+	* made the password strength check more thorough
+
 2005-02-09  Erik Grinaker <erikg@codepoet.no>
 
 	* make undo actually for for edit actions
 0.4.x:
 - string cleanups
 - add "password strength" dialog
-- password checker should check capital/small letters etc
 - add import/export of PasswordSafe files
 - add import/export of GPasMan files
 - add import/export of zsafe files
+- add import/export of gnukeyring
 - sorting of the tree
 - update documentation
 - gnome panel applets (account lookup, password generator etc)
 - why does it ask for password when attempting to import gpasman?
 - only copy/paste entries with keyboard shortcut when tree has focus
   (ctrl-c should copy selected label in dataview when focused)
+- bugfix: crash when gnome icon theme is missing or not configured
+- option to edit instead of run on doubleclick
+- revisit the copy chain etc ui
+- bugfix: don't use lambda for delete_event (may crash on quit)
+- bugfix: gnome.libgnome_module_info_get() removed in new gnome-python
+- clean up the build-system
 
 
 0.5.x:
 def check_password(password):
 	"Checks if a password is valid"
 
-	def palindrome(s):
-		for i in range(len(s)):
-			if s[i] != s[-i - 1]:
-				return False
-		return True
+	# check for length
+	if len(password) < 6:
+		raise ValueError, "is too short"
 
-	def simple(new):
-		min_length	= 9
-		dig_credit	= 1
-		up_credit	= 1
-		low_credit	= 1
-		oth_credit	= 1
 
-		digits = 0
-		uppers = 0
-		lowers = 0
-		others = 0
+	# check for different characters
+	chars = {}
+	for char in password:
+		if not chars.has_key(char):
+			chars[char] = 0
 
-		for c in new:
-			if c in string.digits:
-				digits = digits + 1
-			elif c in string.ascii_uppercase:
-				uppers = uppers + 1
-			elif c in string.ascii_lowercase:
-				lowers = lowers + 1
-			else:
-				others = others + 1
+		chars[char] += 1
 
-		# The scam was this - a password of only one character type
-		# must be 8 letters long.  Two types, 7, and so on.
-		# This is now changed, the base size and the credits or defaults
-		# see the docs on the module for info on these parameters, the
-		# defaults cause the effect to be the same as before the change
+	if len(chars) < 6:
+		raise ValueError, "has too few different characters"
 
-		if dig_credit >= 0 and digits > dig_credit:
-			digits = dig_credit
 
-		if up_credit >= 0 and uppers > up_credit:
-			uppers = up_credit
+	# check if the password is a palindrome
+	for i in range(len(password)):
+		if password[i] != password[-i - 1]:
+			break
 
-		if low_credit >= 0 and lowers > low_credit:
-			lowers = low_credit
+	else:
+		raise ValueError, "is a palindrome"
 
-		if oth_credit >= 0 and others > oth_credit:
-			others = oth_credit
 
-		size = min_length
+	# check the password strength
+	limit		= 10
+	cred_lower	= 1.0
+	cred_upper	= 1.4
+	cred_digit	= 2.0
+	cred_other	= 3.0
 
-		if dig_credit >= 0:
-			size = size - digits
-		elif digits < (dig_credit * -1):
-			return True
- 
-		if up_credit >= 0:
-			size = size - uppers
-		elif uppers < (up_credit * -1):
-			return True
- 
-		if low_credit >= 0:
-			size = size - lowers
-		elif lowers < (low_credit * -1):
-			return True
 
-		if oth_credit >= 0:
-			size = size - others
-		elif others < (oth_credit * -1):
-			return True
+	cred = 0
 
-		if len(new) < size:
-			return True
+	for c in password:
+		if c in string.ascii_lowercase:
+			cred += cred_lower
 
-		return False
+		elif c in string.ascii_uppercase:
+			cred += cred_upper
 
+		elif c in string.digits:
+			cred += cred_digit
+
+		else:
+			cred += cred_other
+
+	if cred < limit:
+		raise ValueError, "is too weak"
+
+
+	# check password with cracklib
 	try:
 		crack.FascistCheck(password)
 
 		pass
 
 
-	if palindrome(password):
-		raise ValueError, "is a palindrome"
-
-	if simple(password):
-		raise ValueError, "is too simple"
-
-
-	return True
-
-
 def dom_text(node):
 	"Returns text content of a DOM node"