UNPKG

consumerportal

Version:

mydna Custimised for you

81 lines (68 loc) 1.75 kB
/// <reference path="../../includes.ts" /> module passwordStrengthSrvc{ export interface IPasswordStrengthService { checkStrength(password: any): any; } export class PasswordStrengthService implements IPasswordStrengthService { strengthObj: any; constructor() { var vm = this; vm.strengthObj = {}; } checkStrength(password) { if (password == null || password.length == 0){ this.strengthObj = { className: "", userText: "" } return this.strengthObj; } if (password.length < 8) { this.strengthObj = { className: "short", userText: "Too short" } return this.strengthObj; } var passwordStrengthValue = 0; var specialCharacters = /[$-/:-?{-~!"^_`\[\]]/g; if (/[0-9]+/.test(password)){ passwordStrengthValue++; } if (/[a-z]+/.test(password)) { passwordStrengthValue++; } if (/[A-Z]+/.test(password)){ passwordStrengthValue++; } if (specialCharacters.test(password)) { passwordStrengthValue++; } if(passwordStrengthValue <= 1){ this.strengthObj = { className: "weak", userText: "Weak" } } else if (passwordStrengthValue == 2) { this.strengthObj = { className: "medium", userText: "Better" } } else if (passwordStrengthValue == 3) { this.strengthObj = { className: "medium", userText: "Medium" } } else if (passwordStrengthValue >= 4) { this.strengthObj = { className: "strong", userText: "Strong" } } return this.strengthObj; } } angular.module('passwordStrengthSrvc', []).service('passwordStrengthSrvc', PasswordStrengthService); }