diff --git a/index.html b/index.html index c369e0920..ed5abe484 100644 --- a/index.html +++ b/index.html @@ -230,7 +230,7 @@

Join a Wallet in Creation

- +
@@ -316,7 +316,7 @@
diff --git a/js/directives.js b/js/directives.js index f1f5bbee8..c99a5bd93 100644 --- a/js/directives.js +++ b/js/directives.js @@ -126,49 +126,30 @@ angular.module('copayApp.directives') restrict: 'EACM', require: 'ngModel', link: function(scope, element, attrs) { - var _grep = function(elems, callback, invert) { - var callbackInverse, - matches = [], - i = 0, - length = elems.length, - callbackExpect = !invert; - - // Go through the array, only saving the items - // that pass the validator function - for (; i < length; i++) { - callbackInverse = !callback(elems[i], i); - if (callbackInverse !== callbackExpect) { - matches.push(elems[i]); - } - } - - return matches; - }; - var strength = { - messages: ['too weak', 'weak', 'weak', 'medium', 'strong'], + messages: ['very weak', 'weak', 'weak', 'medium', 'strong'], colors: ['#c0392b', '#e74c3c', '#d35400', '#f39c12', '#27ae60'], mesureStrength: function (p) { - var _force = 0; - var _regex = /[$-/:-?{-~!"^_`\[\]]/g; - var _lowerLetters = /[a-z]+/.test(p); - var _upperLetters = /[A-Z]+/.test(p); - var _numbers = /[0-9]+/.test(p); - var _symbols = _regex.test(p); - var _flags = [_lowerLetters, _upperLetters, _numbers, _symbols]; - var _passedMatches = _grep(_flags, function (el) { return el === true; }).length; + var force = 0; + var regex = /[$-/:-?{-~!"^_`\[\]]/g; + var lowerLetters = /[a-z]+/.test(p); + var upperLetters = /[A-Z]+/.test(p); + var numbers = /[0-9]+/.test(p); + var symbols = regex.test(p); + var flags = [lowerLetters, upperLetters, numbers, symbols]; + var passedMatches = flags.filter(function (el) { return !!el; }).length; - _force += 2 * p.length + ((p.length >= 10) ? 1 : 0); - _force += _passedMatches * 10; + force = 2 * p.length + (p.length >= 10 ? 1 : 0); + force += passedMatches * 10; // penality (short password) - _force = (p.length <= 6) ? Math.min(_force, 10) : _force; + force = (p.length <= 6) ? Math.min(force, 10) : force; // penality (poor variety of characters) - _force = (_passedMatches == 1) ? Math.min(_force, 10) : _force; - _force = (_passedMatches == 2) ? Math.min(_force, 20) : _force; - _force = (_passedMatches == 3) ? Math.min(_force, 40) : _force; - return _force; + force = (passedMatches == 1) ? Math.min(force, 10) : force; + force = (passedMatches == 2) ? Math.min(force, 20) : force; + force = (passedMatches == 3) ? Math.min(force, 40) : force; + return force; }, getColor: function (s) { var idx = 0; diff --git a/test/unit/directives/directivesSpec.js b/test/unit/directives/directivesSpec.js index 4f3b76d82..f6bc00bc0 100644 --- a/test/unit/directives/directivesSpec.js +++ b/test/unit/directives/directivesSpec.js @@ -63,4 +63,39 @@ describe("Unit: Testing Directives", function() { }); }); + describe('Password strength', function() { + beforeEach(inject(function($compile, $rootScope) { + $scope = $rootScope; + var element = angular.element( + '' + ); + $compile(element)($scope); + $scope.$digest(); + })); + + it('should check very weak password', function() { + $scope.password = 'asd'; + $scope.$digest(); + expect($scope.passwordStrength).to.equal('very weak'); + }); + + it('should check weak password', function() { + $scope.password = 'asdasdASDASD'; + $scope.$digest(); + expect($scope.passwordStrength).to.equal('weak'); + }); + + it('should check medium password', function() { + $scope.password = 'asdasdASDASD1'; + $scope.$digest(); + expect($scope.passwordStrength).to.equal('medium'); + }); + + it('should check strong password', function() { + $scope.password = 'asdasdASDASD1{'; + $scope.$digest(); + expect($scope.passwordStrength).to.equal('strong'); + }); + + }); });