0.5.1 • Published 1 year ago

angular-password-strength-analyzer v0.5.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Setting up in module's imports

import {AngularPasswordStrengthAnalyzerModule} from "angular-password-strength-analyzer";

AngularPasswordStrengthAnalyzerModule

Usage Password analyzer in ts

import {pwdWeightAnalyze, pwdWeightAnalyzeWithTitle} from "angular-password-strength-analyzer";

public password: string | null | undefined;
public passwordWeight: number | null | undefined;
public passwordStrength: string | null | undefined;
public passwordStrengthCustom: string | null | undefined;
public passwordWeightCustom: number | null | undefined;

checkPasswordStrength(): void {
  this.passwordWeight = pwdWeightAnalyze(this.password);
  this.passwordWeightCustom = pwdWeightAnalyze(this.password, 6);
  this.passwordStrength = pwdWeightAnalyzeWithTitle(this.password);
  this.passwordStrengthCustom = pwdWeightAnalyzeWithTitle(this.password, 6, [
    { max: 0, text: 'your text 1' },
    { min: 0, max: 30, text: 'your text 2' },
    { min: 30, max: 60, text: 'your text 3' },
    { min: 60, text: 'your text 4' },
  ]);
}

Usage Password analyzer in html

<input
  type="password"
  [(ngModel)]="password"
  (ngModelChange)="checkPasswordStrength()">
<p>Weight: {{passwordWeight}}</p>
<p>Strength is: {{passwordStrength}}</p>
<p>Custom Weight is: {{passwordWeightCustom}}</p>
<p>Custom Strength is: {{passwordStrengthCustom}}</p>
 NOTE: For password handling you can use `ngModel`, `rxjs` etc.

Usage pwdWeightAnalyze function

This is a TypeScript function that analyzes the strength of a password based on certain criteria and returns a score.

Criterias

  • If the password contains at least 3 digits
  • If the password contains at least 2 symbols
  • If the password contains both upper and lowercase letters
  • If the password contains both letters and digits
  • If the password contains both symbols and digits
  • If the password contains both letters and symbols
  • If the password consists only of letters or only of digits
NOTE: These criteria can be changed by specifying `analyzerOptions` in `pwdWeightAnalyze` and `pwdWeightAnalyzeWithTitle` functions
KeyTypeOptionalDefault value
pwdstringnoN/A
minLengthnumberyes8
analyzerOptionsIPasswordAnalyzerOptionsyesdefault

Output value is number - password's complexity

Usage pwdWeightAnalyzeWithTitle function

This is a TypeScript function that analyzes the strength of a password based on certain criteria and returns a score expressed in words.

Criterias

  • If the password weight is 0, then it is "empty"
  • If the password weight is greater than 1 and less than 34, then it is "weak"
  • If the password weight is greater than or equal to 35 and less than 67, then it is "good".
  • If the password weight is greater than or equal to 68, then it is "excellent"
NOTE: These criteria can be changed by specifying `options` in `pwdWeightAnalyzeWithTitle` function
KeyTypeOptionalDefault value
pwdstringnoN/A
minLengthnumberyes8
optionsIPasswordStrengthOptions[]yesdefault
analyzerOptionsIPasswordAnalyzerOptionsyesdefault

Output value is string - password's complexity's title

IPasswordAnalyzerOptions model

KeyTypeOptionalDefault value
isActiveOptionCountDigitsbooleanyestrue
isActiveOptionCountSpecialCharsbooleanyestrue
isActiveOptionHasUpperCaseAndLowerCasebooleanyestrue
isActiveOptionHasLettersAndDigitsbooleanyestrue
isActiveOptionHasSpecialCharsAndDigitsbooleanyestrue
isActiveOptionHasLettersAndSpecialCharsbooleanyestrue
isActiveOptionIsAllLettersOrAllDigitsbooleanyestrue

IPasswordStrengthOptions model

KeyTypeOptionalDefault value
minbooleanyesN/A
maxbooleanyesN/A
textbooleannoN/A

Default model for IPasswordStrengthOptions[]

[
  { max: 0, text: 'empty' }, // don't remove it 
  { min: 1, max: 1, text: 'too short' }, // don't remove it 
  { min: 2, max: 34, text: 'weak' }, // your values
  { min: 35, max: 67, text: 'good' }, // your values
  { min: 68, text: 'excellent' }, // your values
]
NOTE: For empty password IPasswordStrengthOptions should be with max = 0
NOTE: For a password of insufficient length IPasswordStrengthOptions should be with min = 1 max = 1

Examples

PasswordpwdWeightAnalyzepwdWeightAnalyzeWithTitleDescription
mz.5J#[t97excellent
PjCvz2Qf27weak
p@$$word16weak
12345678902weak
doggiesRcute!46good
00000000000000000000000000000A3weak
01too shortminLen = 2
002weakminLen = 2
0002weakminLen = 2
00002weakminLen = 2
000002weakminLen = 2
0.5.1

1 year ago

0.5.0

1 year ago