Erik Grinaker avatar Erik Grinaker committed 512fcbd

minor improvements to password checking

Comments (0)

Files changed (4)

 
 	* use stock gtk icon sizes instead of custom ones
 
+	* minor improvements to password checking
+
 2006-01-20  Erik Grinaker <erikg@codepoet.no>
 
 	* strip xml entities from password on clipboard copy or
 New features:
 - new applet option to show/hide search entry
 - use icons instead of colors in password entries to indicate strength
+- minor improvements to password checking
 
 Bugfixes:
 - fixed drag and drop undo/redo crashes

src/lib/dialog.py

 				result	= "The password seems good"
 
 		except ValueError, result:
-			result	= str(result)
-			result = result.replace("simplistic/systematic", "systematic")
-			result = result.replace(" dictionary", "")
-
-			if result[:3] == "it ":
-				result = result[3:]
-
 			icon	= ui.STOCK_PASSWORD_WEAK
-			result = "The password " + result
+			result = "The password " + str(result)
 
 		self.result.set_text(result)
 		self.result.set_stock(icon, ui.ICON_SIZE_LABEL)
 
 
 
-def check_password(password, check_len = True, check_var = True, check_str = True, check_crack = True):
+def check_password(password):
 	"Checks if a password is valid"
 
 	# check for length
-	if check_len == True:
-		if len(password) < 6:
-			raise ValueError, "is too short"
+	if len(password) < 5:
+		raise ValueError, "is too short"
 
 
 	# check for different characters
-	if check_var == True:
+	chars = []
+	for char in password:
+		if char not in chars:
+			chars.append(char)
 
-		chars = {}
-		for char in password:
-			if not chars.has_key(char):
-				chars[char] = 0
+	if len(chars) < 5:
+		raise ValueError, "isn't varied enough"
 
-			chars[char] += 1
 
-		if len(chars) < 6:
-			raise ValueError, "isn't varied enough"
+	# check if the password is a palindrome
+	for i in range(len(password)):
+		if password[i] != password[-i - 1]:
+			break
 
+	else:
+		raise ValueError, "is a palindrome"
 
-		# check if the password is a palindrome
-		for i in range(len(password)):
-			if password[i] != password[-i - 1]:
-				break
+
+	# check the password strength
+	limit		= 10
+	cred_lower	= 1.1
+	cred_upper	= 1.4
+	cred_digit	= 2.0
+	cred_other	= 3.0
+
+	cred = 0
+
+	for c in password:
+		if c in string.ascii_lowercase:
+			cred += cred_lower
+
+		elif c in string.ascii_uppercase:
+			cred += cred_upper
+
+		elif c in string.digits:
+			cred += cred_digit
 
 		else:
-			raise ValueError, "is a palindrome"
+			cred += cred_other
 
-
-	# check the password strength
-	if check_str == True:
-		limit		= 10
-		cred_lower	= 1.1
-		cred_upper	= 1.4
-		cred_digit	= 2.0
-		cred_other	= 3.0
-
-
-		cred = 0
-
-		for c in password:
-			if c in string.ascii_lowercase:
-				cred += cred_lower
-
-			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"
+	if cred < limit:
+		raise ValueError, "is too weak"
 
 
 	# check password with cracklib
-	if check_crack == True:
-		try:
-			crack.FascistCheck(password)
+	try:
+		crack.FascistCheck(password)
 
-		except IOError:
-			pass
+	except ValueError, reason:
+
+		# modify reason
+		reason = str(reason).strip()
+		reason = reason.replace("simplistic/systematic", "systematic")
+		reason = reason.replace(" dictionary", "")
+
+		if reason[:3] == "it ":
+			reason = reason[3:]
+
+		if reason[:5] == "it's ":
+			reason = "is " + reason[5:]
+
+		raise ValueError, reason
+
+	except IOError:
+		pass
 
 
 def dom_text(node):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.