{"id":19972363,"url":"https://github.com/tarunbatra/password-validator","last_synced_at":"2025-05-14T20:04:11.648Z","repository":{"id":39581699,"uuid":"55300739","full_name":"tarunbatra/password-validator","owner":"tarunbatra","description":"Validates password according to flexible and intuitive specification","archived":false,"fork":false,"pushed_at":"2024-12-17T17:50:45.000Z","size":1151,"stargazers_count":285,"open_issues_count":8,"forks_count":42,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-06T11:04:55.624Z","etag":null,"topics":["nodejs","npm","password","password-validator","schema","validate","validation","validation-library"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/password-validator","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tarunbatra.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-02T15:08:11.000Z","updated_at":"2025-02-19T21:26:54.000Z","dependencies_parsed_at":"2024-10-23T05:47:02.543Z","dependency_job_id":"e52c04d8-f157-4d38-b115-8b8caacfe697","html_url":"https://github.com/tarunbatra/password-validator","commit_stats":{"total_commits":170,"total_committers":13,"mean_commits":"13.076923076923077","dds":0.1588235294117647,"last_synced_commit":"75af54001442b932e52f2ac502e7e5bc16b4ca1b"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarunbatra%2Fpassword-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarunbatra%2Fpassword-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarunbatra%2Fpassword-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarunbatra%2Fpassword-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarunbatra","download_url":"https://codeload.github.com/tarunbatra/password-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625499,"owners_count":21135513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","npm","password","password-validator","schema","validate","validation","validation-library"],"created_at":"2024-11-13T03:07:48.021Z","updated_at":"2025-04-13T15:09:00.206Z","avatar_url":"https://github.com/tarunbatra.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"[![logo][logo-image]][logo-url]\n\n[![npm version][npm-image]][npm-url]\n[![npm downloads][downloads-image]][npm-url]\n![gh action build status][gh_build-url]\n[![coverage status][codecov-image]][codecov-url]\n\n## Install\n`npm install password-validator`\n\n## Usage\n```js\nvar passwordValidator = require('password-validator');\n\n// Create a schema\nvar schema = new passwordValidator();\n\n// Add properties to it\nschema\n.is().min(8)                                    // Minimum length 8\n.is().max(100)                                  // Maximum length 100\n.has().uppercase()                              // Must have uppercase letters\n.has().lowercase()                              // Must have lowercase letters\n.has().digits(2)                                // Must have at least 2 digits\n.has().not().spaces()                           // Should not have spaces\n.is().not().oneOf(['Passw0rd', 'Password123']); // Blacklist these values\n\n// Validate against a password string\nconsole.log(schema.validate('validPASS123'));\n// =\u003e true\nconsole.log(schema.validate('invalidPASS'));\n// =\u003e false\n\n// Get a full list of rules which failed\nconsole.log(schema.validate('joke', { list: true }));\n// =\u003e [ 'min', 'uppercase', 'digits' ]\n\n```\n\n## Advanced usage\n### Details about failed validations\nSometimes just knowing that the password validation failed or what failed is not enough and it is important to get more context. In those cases the `details` option can be used to get more details about what failed.\n\n```js\nconsole.log(schema.validate('joke', { details: true }));\n```\nThe above code will output:\n```js\n[\n  {\n    validation: 'min',\n    arguments: 8,\n    message: 'The string should have a minimum length of 8 characters'\n  },\n  {\n    validation: 'uppercase',\n    message: 'The string should have a minimum of 1 uppercase letter'\n  },\n  {\n    validation: 'digits',\n    arguments: 2,\n    message: 'The string should have a minimum of 2 digits'\n  }\n]\n```\n### Custom validation messages\nThe validation messages can be overriden by providing a description of the validation. For example:\n```js\nschema.not().uppercase(8, 'maximum 8 chars in CAPS please')\n```\nThe above validation, on failure, should return the following object:\n```js\n  {\n    validation: 'min',\n    arguments: 8,\n    inverted: true,\n    message: 'maximum 8 chars in CAPS please'\n  },\n```\n\n### Plugins\nPlugin functions can be added to the password validator schema for custom password validation going beyond the rules provided here. For example:\n```js\nvar validator = require('validator');\nvar passwordValidator = require('password-validator');\n\nvar schema = new passwordValidator()\n    .min(3, 'Password too small')\n    .usingPlugin(validator.isEmail, 'Password should be an email');\n\nschema.validate('not-an-email', { details: true })\n// [{ validation: 'usingPlugin', arguments: [Function: isEmail], message: 'Password should be an email' }]\n```\n\n## Rules\nRules supported as of now are:\n\n|     Rules            |               Descriptions                                                                                                       |\n|:---------------------|:---------------------------------------------------------------------------------------------------------------------------------|\n|**digits([count], [description])**   | specifies password must include digits (optionally provide count paramenter to specify at least n digits)                        |\n|**letters([count], [description])**  | specifies password must include letters (optionally provide count paramenter to specify at least n letters)                      |\n|**lowercase([count], [description])**| specifies password must include lowercase letters (optionally provide count paramenter to specify at least n lowercase letters)  |\n|**uppercase([count], [description])**| specifies password must include uppercase letters (optionally provide count paramenter to specify at least n uppercase letters)  |\n|**symbols([count], [description])**  | specifies password must include symbols (optionally provide count paramenter to specify at least n symbols)                      |\n|**spaces([count], [description])**   | specifies password must include spaces (optionally provide count paramenter to specify at least n spaces)                        |\n|**min(len, [description])**          | specifies minimum length                                                                                                         |\n|**max(len, [description])**          | specifies maximum length                                                                                                         |\n|**oneOf(list)**                      | specifies the whitelisted values                                                                                                 |\n|**not([regex], [description])**      | inverts the result of validations applied next                                                                                   |\n|**is()**                             | inverts the effect of _**not()**_                                                                                                |\n|**has([regex], [description])**      | inverts the effect of _**not()**_ and applies a regex (optional)                                                                 |\n|**usingPlugin(fn, [description])**   | Executes custom function and include its result in password validation                                                           |\n\n## Options\nThe following options can be passed to `validate` method:\n* `list` - If set, the validate method returns a list of rules which failed instead of true/false.\n\n## Resources\n* API Reference\n  - [latest](https://tarunbatra.github.io/password-validator)\n  - [others](https://github.com/tarunbatra/password-validator/wiki/API-Reference)\n* [Wiki](https://github.com/tarunbatra/password-validator/wiki)\n* [Changelog](https://github.com/tarunbatra/password-validator/blob/master/CHANGELOG.md)\n\nFor APIs of other older versions, head to Wiki.\n\n## License\n[MIT License](https://choosealicense.com/licenses/mit/)\n\n\n[logo-image]: https://res.cloudinary.com/tbking/image/upload/v1490803400/password-validator/logo.png\n[logo-url]: https://tarunbatra.github.io/password-validator\n[npm-image]: https://img.shields.io/npm/v/password-validator.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/password-validator\n[downloads-image]: https://img.shields.io/npm/dt/password-validator.svg?style=flat-square\n[codecov-url]: https://codecov.io/gh/tarunbatra/password-validator\n[codecov-image]: https://img.shields.io/codecov/c/gh/tarunbatra/password-validator?logo=codecov\u0026style=flat-square\n[gh_build-url]: https://img.shields.io/github/workflow/status/tarunbatra/password-validator/build-ci?style=flat-square\u0026logo=github\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarunbatra%2Fpassword-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarunbatra%2Fpassword-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarunbatra%2Fpassword-validator/lists"}