Permalink
Browse files

Fix entropy calculation bug

The strength increased and suddenly it dropped.
  • Loading branch information...
1 parent b6fe46e commit ba062245b1041259888d735da7431d4d5444dd92 @trimentor committed Nov 7, 2013
Showing with 20 additions and 17 deletions.
  1. +1 −1 YAPSM.jquery.json
  2. +19 −16 jquery.YAPSM.js
View
@@ -4,7 +4,7 @@
"description": "Take no risk and help your users to choose good passwords!",
"homepage": "https://github.com/trimentor/YAPSM",
"keywords": ["yapsm", "password", "strength", "complexity", "security", "time", "measure", "meter", "validation", "check"],
- "version": "1.0.0",
+ "version": "1.0.1",
"author": {
"name": "trimentor",
"url": "https://github.com/trimentor"
View
@@ -1,5 +1,5 @@
/*!
- * jQuery YAPSM Plugin v1.0.0
+ * jQuery YAPSM Plugin v1.0.1
*
* Copyright 2011, 2013 Kjel Delaey
* Released under the MIT license
@@ -12,7 +12,8 @@
passwordStrengthMeter = new $.yapsm(options);
calculatePasswordComplexity = function () {
- this.complexity = passwordStrengthMeter.strength(this.value);
+ var password = this.value;
+ this.complexity = password.length ? passwordStrengthMeter.strength(password) : "";
};
$(this).keyup(calculatePasswordComplexity);
return this;
@@ -88,19 +89,21 @@
},
strength: function (password) {
- var dictionaryWord, bits;
+ var dictionaryWord, bitsOfEntropy;
dictionaryWord = this.commonWord(password);
- bits = !dictionaryWord ? this.passwordStrength(password) : null;
- return this.strengthClass(bits);
+ bitsOfEntropy = !dictionaryWord ? this.passwordStrength(password) : null;
+ return this.strengthClass(bitsOfEntropy);
},
charSetEntropy: function (charSet) {
return Math.log(charSet) / Math.log(2);
},
passwordStrength: function (password) {
- var charSet = this.numberOfPossibleSymbols(password);
- return this.charSetEntropy(charSet) * password.length;
+ var charSet, bitsOfEntropy;
+ charSet = this.numberOfPossibleSymbols(password);
+ bitsOfEntropy = this.charSetEntropy(charSet) * password.length;
+ return Math.floor(bitsOfEntropy);
},
commonWord: function (password) {
@@ -136,30 +139,30 @@
inclLowerCase = true;
score += this.entropyMap.mixedCaseLettersOnly.count;
}
- if (typeof inclOther === "undefined" && "`~-_=+[{]}\\|;:'\",<.>/?!@#$%^&*()".indexOf(character) >= 0) {
+ if (typeof inclOther === "undefined" && /\W/.test(character)) {
inclOther = true;
score += this.entropyMap.otherCharacters.count;
}
}
return score;
},
- strengthClass: function (bits) {
+ strengthClass: function (bitsOfEntropy) {
var cssClass;
- if (bits === null) {
+ if (bitsOfEntropy === null) {
cssClass = this.settings.commonWordClass;
} else {
- if (bits >= 28 && bits <= 35) {
+ if (bitsOfEntropy <= 27) {
+ cssClass = this.settings.weakClass;
+ } else if (bitsOfEntropy >= 28 && bitsOfEntropy <= 35) {
cssClass = this.settings.fairClass;
- } else if (bits >= 36 && bits <= 59) {
+ } else if (bitsOfEntropy >= 36 && bitsOfEntropy <= 59) {
cssClass = this.settings.goodClass;
- } else if (bits >= 60 && bits <= 127) {
+ } else if (bitsOfEntropy >= 60 && bitsOfEntropy <= 127) {
cssClass = this.settings.strongClass;
- } else if (bits >= 128) {
+ } else if (bitsOfEntropy > 128) {
cssClass = this.settings.veryStrongClass;
- } else {
- cssClass = this.settings.weakClass;
}
}
return cssClass;

0 comments on commit ba06224

Please sign in to comment.