UNPKG

user-registration-component

Version:

WCG -- AngularJS Component Library

88 lines (83 loc) 3.01 kB
'use strict'; angular.module('userRegistrationModule').component('userRegistration', { templateUrl: '/node_modules/user-registration-component/user-registration.template.html', controller: function () { var self = this; self.pwd = ""; self.strength = '100%'; self.score = 0; self.checkUpperCase = function () { for (var c = 0; c < self.pwd.length; c++) { if (self.pwd[c].charCodeAt() >= 65 && self.pwd[c].charCodeAt() <= 91) { return 1; } } return 0; }; self.checkEmpty = function () { var p = self.pwd || ""; if (p.length > 0) { return 1; } return 0; }; self.checkDigit = function () { var p = self.pwd || ""; var digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']; var result = 0; digits.forEach(function(item) { if (p.includes(item)) { result = 1; return; } }); return (result === 0 ? 0: 1); }; self.checkLength = function () { var p = self.pwd || ""; if (p.length >= 8) { return 1; } return 0; }; self.checkSpecialChar = function () { var specChars = ['*', '@', '_', '.']; var p = self.pwd || ""; var result = 0; specChars.forEach(function(item) { if (p.includes(item)) { result = 1; return; } }); return (result === 0 ? 0: 1); }; self.rules = [{ ruleFn: self.checkEmpty, score: 0 }, { ruleFn: self.checkDigit, score: 0 }, { ruleFn: self.checkUpperCase, score: 0 }, { ruleFn: self.checkSpecialChar, score: 0 }, { ruleFn: self.checkLength, score: 0 }]; self.checkStrength = function () { self.score = 0; var runningTotal = 0; self.rules.forEach(function (item) { item.score = item.ruleFn(); runningTotal += item.score; console.log("runningTotal:" + runningTotal); self.strength = (100 - ((runningTotal / self.rules.length) * 100)) + '%'; }, self); }; } });