UNPKG

osmos

Version:

OSMOS - Symbiosys

63 lines (52 loc) 1.93 kB
import { inject } from 'aurelia-framework'; import { IdentityManager } from './identityManager'; @inject(IdentityManager) export class PasswordValidation { constructor(identityManager){ this.passwordValidationRules = identityManager.passwordValidationRules; } lengthOk(password) { if (!this.passwordValidationRules) return true; if (!this.passwordValidationRules.requiredLength) return true; if (!password) return false; return password.length >= this.passwordValidationRules.requiredLength; } digitsOk(password) { if (!this.passwordValidationRules) return true; if (!this.passwordValidationRules.requireDigit) return true; if (!password) return false; return /\d/.test(password); } upperOk(password) { if (!this.passwordValidationRules) return true; if (!this.passwordValidationRules.requireUppercase) return true; if (!password) return false; return /[A-Z]/.test(password); } lowerOk(password) { if (!this.passwordValidationRules) return true; if (!this.passwordValidationRules.requireLowercase) return true; if (!password) return false; return /[a-z]/.test(password); } specialOk(password) { if (!this.passwordValidationRules) return true; if (!this.passwordValidationRules.requireNonAlphanumeric) return true; if (!password) return false; return /[\W_]+/.test(password); } isOk(password) { let result = this.lengthOk(password) && this.digitsOk(password) && this.upperOk(password) && this.lowerOk(password) && this.specialOk(password); return result; } isValid(password){ return { lengthOk: this.lengthOk(password), digitsOk: this.digitsOk(password), upperOk: this.upperOk(password), lowerOk: this.lowerOk(password), specialOk: this.specialOk(password), isOk: this.isOk(password) }; } }