passman/js/vendor/ng-password-meter/ng-password-meter.js

85 lines
2 KiB
JavaScript
Raw Normal View History

2016-09-12 05:40:06 +08:00
(function() {
'use strict';
/* global _ */
/**
* @ngdoc directive
* @name ngPasswordMeter.directive:ngPassworMeter
* @description
* Simple and elegant password strength meter from the Lifekees
* Password Manager
*/
angular.module('ngPasswordMeter', [])
.directive('ngPasswordMeter', function() {
return {
2016-09-12 06:23:06 +08:00
templateUrl: 'views/partials/password-meter.html',
2016-09-12 05:40:06 +08:00
restrict: 'E',
scope: {
password: '=',
strength: '=?',
},
link: function(scope) {
2016-09-12 06:23:06 +08:00
scope.scoreShown = false;
scope.toggleScore = function(){
scope.scoreShown = !scope.scoreShown;
}
2016-09-12 05:40:06 +08:00
2016-09-12 06:23:06 +08:00
var measureStrength = function(p) {
console.log();
if(p){
var _score = zxcvbn(p)
2016-09-12 05:40:06 +08:00
}
2016-09-12 06:23:06 +08:00
console.log(_score.score);
return _score;
2016-09-12 05:40:06 +08:00
};
scope.colClass = '';
scope.masterClass = '';
scope.$watch('password', function() {
scope.first = '';
scope.second = '';
scope.third = '';
scope.fourth = '';
scope.message = '';
if (!scope.password) {
scope.masterClass = 'hidden';
return;
}
2016-09-12 06:23:06 +08:00
var _score = measureStrength(scope.password);
scope.score = _score;
scope.strength = _score.score;
2016-09-12 05:40:06 +08:00
scope.masterClass = '';
2016-09-12 06:23:06 +08:00
if (scope.strength == 0) {
2016-09-12 05:40:06 +08:00
scope.first = 'poor';
2016-09-12 19:21:41 +08:00
scope.message = 'poor';
2016-09-12 06:23:06 +08:00
} else if (scope.strength == 1) {
scope.first = 'poor';
scope.second = 'poor';
scope.message = 'poor';
} else if (scope.strength == 2) {
2016-09-12 05:40:06 +08:00
scope.first = 'weak';
scope.second = 'weak';
scope.message = 'weak';
2016-09-12 06:23:06 +08:00
} else if (scope.strength == 3) {
2016-09-12 05:40:06 +08:00
scope.first = 'good';
scope.second = 'good';
scope.third = 'good';
scope.message = 'good';
2016-09-12 06:23:06 +08:00
} else if (scope.strength == 4) {
2016-09-12 05:40:06 +08:00
scope.first = 'strong';
scope.second = 'strong';
scope.third = 'strong';
scope.fourth = 'strong';
scope.message = 'strong';
}
});
},
};
});
})();