Skip to content

The password validator is a pop-up window that appears when you start typing in input box. Here you can configure the password acceptance criteria, once your enter characters fullfil the requirement you will get a success message.

License

Notifications You must be signed in to change notification settings

jaganbishoyi/ngx-password-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Password validator for Angular

npm GitHub Contributors GitHub language count npm bundle size GitHub repo size npm NPM GitHub last commit contributions welcome

The password validator is a pop-up window that appears when you start typing in input box. Here you can configure the password acceptance criteria, once your enter characters fullfil the requirement you will get a success message.

Help to make Password Validator better by answering a few questions.

Demo

https://jaganbishoyi.github.io/ngx-password-validator/

Installation

Install the npm package.

npm i ng-password-validator

Import in NgModule:

import { NgPasswordValidatorModule } from 'ng-password-validator';

@NgModule({
    imports: [ NgPasswordValidatorModule ]
})

Usage

Options can be set in the directive tag, so they have the highest priority.

<input type="text" id="password" name="password" placeholder="Password.."
    NgPasswordValidator>

You may pass as an object:

<input type="text" id="password" name="password" placeholder="Password.."
    [NgPasswordValidator]="options">

Password type as 'range':

options = {
    'placement': 'top',
    'rules': {
        'password': {
            'type': "range",
            'min': 6,
            'max': 10,
            // No need to pass length
        }
    },
    'shadow': false,
    'offset': 15,
}

Password type as 'number':

options = {
    'placement': 'top',
    'rules': {
        'password': {
            'type': "number",
            'length': 8,
            // No need to pass min and max
        }
    },
    'shadow': false,
    'offset': 15,
}

Template( Default value is popup ):

<input type="text" id="password" name="password" placeholder="Password.."
    [NgPasswordValidator]="options">

Template as 'inline':

options = {
    'template': 'inline',
    'theme': 'pro'
}

Template as 'popup':

options = {
    'template': 'popup',
    'theme': 'pro'
}

Theming( Default value is pro ):

<input type="text" id="password" name="password" placeholder="Password.."
    [NgPasswordValidator]="options">

Theme as 'basic':

options = {
    'placement': 'top',
    'theme': 'basic'
}

Theme as 'pro':

options = {
    'placement': 'top',
    'theme': 'pro'
}

You can also change Popup header and success message:

<input type="text" id="password" name="password" placeholder="Password.."
    [NgPasswordValidator]="options">
options = {
    'heading': 'Password Requirement',
    'successMessage': 'Wow! Password is Strong.'
}

After closing the popup window, you will get one output for password validity (true/false):

<input type="text" id="password" name="password" placeholder="Password.."
    NgPasswordValidator (valid)="isValid($event)">
isValid(event: boolean) {
    this.isPasswordValid = event;
}

Custom class configuration

In Component HTML file

<input type="text" id="password" name="password" placeholder="Password.."
    [NgPasswordValidator]="options">

In Component TS file

options = {
    'custom-class': 'custom-class',
}

In Component SCSS file

::ng-deep {
    .custom-class {
        .popup-window {
            .heading {
                color: red !important;
                font-family: cursive;
            }
        }
    }
}

Set default values

In app.module.ts export the default options like below:

import { NgPasswordValidatorModule, NgPasswordValidatorOptions } from "ng-password-validator";

export const MyDefaultOptions: NgPasswordValidatorOptions = {
    placement: "right",
    rules: {
        'password': {
            'type': "range",
            'min': 6,
            'max': 10,
        },
        "include-symbol": true,
        "include-number": false,
        "include-lowercase-characters": true,
        "include-uppercase-characters": false,
    }
};

And pass your parameters when importing the module:

@NgModule({
    imports: [
      NgPasswordValidatorModule.forRoot(MyDefaultOptions as NgPasswordValidatorOptions)
    ]
})

Properties

name type default description
placement "top", "bottom", "left", "right" "bottom" The position of the popup window.
template "inline", "popup" "popup" Password template
z-index number 0 Z-index of the popup window.
trigger "focus" Specifies how the popup window is triggered.
custom-class string Classes to be passed to the popup window.
heading string Password Policy Heading of popup window.
successMessage string Awesome! Password requirement fulfilled. Success message after requirements fulfilled.
animation-duration number 300 The duration controls how long the animation takes to run from start to finish.
theme "basic" "basic" Theme of popup window background and text.
shadow boolean true Shadow of the popup window.
offset number 8 Offset the popup window relative to the item.
width number undefined Width of the popup window.
max-width number 390 Maximum width of the popup window.
pointerEvents "auto", "none" "none" Defines whether or not an element reacts to pointer events.
position {top: number, left: number} undefined The popup window coordinates relative to the browser window.

Events

When you call events, the delays that are specified in the options in the directive are taken into account.

Event Description
{type: "show", position: DOMRect} The event is called before the popup window appears.
{type: "shown", position: DOMRect} The event is called after the animation of the appearance of the popup window.
{type: "hide", position: DOMRect} The event is called before the popup window is hidden.
{type: "hidden", position: DOMRect} The event is called after the animation of the popup window is hidden.

For any questions, suggestions, or feature requests

Please file an issue!

License

License under the MIT License (MIT)

Copyright (c) 2020-2022 Jagan Mohan Bishoyi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

The password validator is a pop-up window that appears when you start typing in input box. Here you can configure the password acceptance criteria, once your enter characters fullfil the requirement you will get a success message.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published