Check Passwords
Tool for check passwords in form fields using webpack
and pure javascript in the client.
Installation
Via npm npm install check-passwords
Usage and API documentation
This tool is make for will used with webpack
as a module.
The class CheckPasswords
It's the main class and receive as paramater an object of configuration, this object can have the following properties and method.
target
{DOMObject}, This should be the form DOM object and is optional, if is undefined then the form DOM object will be the first form element that exists at body
.passwordFields
{Array}, This should be the array of inputs fields type password and is optional, if is undefined then the inputs will be the first two in form
.onMatch
{Function}, This function is called when the password in the two fields are equals.onDontMatch
{Function}, This function is called when the password in the two fields aren't equals.
The method watch
is for listen the event blur in the second field when this change it, after that the functions onMatch
and onDontMatch
are called if the passwords equals or not.
Example
const CheckPasswords = require('check-passwords');
window.onload = function () {
const MyCheckPass = new CheckPasswords({
target: document.getElementById('form'),
passwordFields: [
document.querySelector('.password'),
document.querySelector('.repear-password')
],
onMatch: function () {
},
onDontMatch: function () {
}
});
MyCheckPass.watch();
};
Test
You need have installed globaly webpack
and execute npm run test
for test the tool in your browser.
License
MIT