{"_id":"@ancientec/password-policy-js","_rev":"2-2c9dba2fbc9ad4ab6345c96e5d58d0a6","name":"@ancientec/password-policy-js","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@ancientec/password-policy-js","description":"helper function to generate password policies and validate against password","version":"1.0.0","keywords":["password","policy","rules","validation"],"author":{"name":"Ancientec Co., Ltd."},"main":"dist/password_policy.js","types":"dist/password_policy.d.ts","license":"MIT","repository":{"type":"git","url":"git+https://github.com/ancientec/password-policy-js.git"},"scripts":{"clean":"(rm -r ./dist || true)","clean:all":"npm run clean && (rm -r ./node_modules || true)","build":"npm run clean &&  tsc && npm run esbuild-browser","esbuild-browser":"esbuild src/browser.js --bundle --minify --outfile=dist/password_policy.min.js","docs":"typedoc --entryPoints src/password_policy.ts","test":"mocha -r ts-node/register test/**/*.ts"},"devDependencies":{"@types/chai":"^4.2.21","@types/mocha":"^9.0.0","chai":"^4.1.2","esbuild":"^0.12.22","eslint":"^6.3.0","mocha":"^9.0.0","source-map-support":"^0.5.12","ts-node":"^10.0.0","typedoc":"^0.21.6","typescript":"^4.3.5"},"gitHead":"26865bf91b555411093da30da85171cc6ee777cb","bugs":{"url":"https://github.com/ancientec/password-policy-js/issues"},"homepage":"https://github.com/ancientec/password-policy-js#readme","_id":"@ancientec/password-policy-js@1.0.0","_nodeVersion":"16.2.0","_npmVersion":"7.13.0","dist":{"integrity":"sha512-79djRQC4IXfyIGjuU7Q20JfBmjwVsd/Fh18b+FHn2o5SiKRz8r9NadC7K5ASgBJqIteeSUfpJe51jRRMzMBdaw==","shasum":"88a9b6e72875165714c8df782ebbfad07cd8d235","tarball":"https://registry.npmjs.org/@ancientec/password-policy-js/-/password-policy-js-1.0.0.tgz","fileCount":15,"unpackedSize":57221,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhKIMCCRA9TVsSAnZWagAAH7gQAINzOOv39bhMbuOaCaQi\n4DtEuKJ4p6lW0ZtKkgfB8dkUsGSnFOZqSPLVXbfdX27LZQ3EqftZQfLegQeY\nxJg+zcRruLtVP8EV4U+EDmsfEbktaMQc83ZYmLdTZDns32JL+i1wFJvgvppl\nyiGHo92lIoLCDT+U3RUkJdCNZ6E0nqHBg/rJ7vIINouLZzm7pqmAyp7q/QJc\nwMMtZYPDGu43iUGFqkgXqsgmQu1mKD+IyGUYGB70mjY919m7Iy9OAmhxEp1X\nwmacdQmPOo2nxvKgwQjl3HBNSqud9u0i2A1NDDAdFkpW7PUuKjWH3YMO7j+z\njd56OspI0DnYCiQNrCSjOz6vf5N5+11+RqFDN7m5C1UhW7Lm1K5Hm1nl2DEb\nYxj1mXqS3dPyMu7+CMpxDKZQ5YGjvIoqfflYLAAzFmPeED8b1Ozki27OH5iG\nETByVxwa574i1umBmHZm8i8g0itmhroTfgyseVy3SOiuboVPycvslVrIoFdF\n7mhMrTSA1Qer6LKW5J3DhOCo2X2LADJmZaEdVPuZlci7/w+jnemMrgdh1fai\nDdGB6m/uFm1CJHEbTRIA6918/QCdrH5dkCdU0yGIGQCAE6am6+tuIRKnJcOF\ncYgsSG7/6uoxskHCb3AaTDhZ7i60yHupqpl9PjWVJrzWgo5JT18tOey084GJ\n16m/\r\n=mx4P\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHlIeOHCJC+CcyGBZoE5IOTlgttX17zWQFXC0H0tvXI3AiEAzR4Y+mxR8X2LmZvjiLw9q6K01Fz56IAGKu3ojOJ9Nu8="}]},"_npmUser":{"name":"ancientec","email":"open@ancientec.com"},"directories":{},"maintainers":[{"name":"ancientec","email":"open@ancientec.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/password-policy-js_1.0.0_1630044930595_0.5549963364252852"},"_hasShrinkwrap":false},"1.0.1":{"name":"@ancientec/password-policy-js","description":"helper function to generate password policies and validate against password","version":"1.0.1","keywords":["password","policy","rules","validation"],"author":{"name":"Ancientec Co., Ltd."},"main":"dist/password_policy.js","types":"dist/password_policy.d.ts","license":"MIT","repository":{"type":"git","url":"git+https://github.com/ancientec/password-policy-js.git"},"scripts":{"clean":"(rm -r ./dist || true)","clean:all":"npm run clean && (rm -r ./node_modules || true)","build":"npm run clean &&  tsc && npm run esbuild-browser","esbuild-browser":"esbuild src/browser.js --bundle --minify --outfile=dist/password_policy.min.js","docs":"typedoc --entryPoints src/password_policy.ts","test":"mocha -r ts-node/register test/**/*.ts"},"devDependencies":{"@types/chai":"^4.2.21","@types/mocha":"^9.0.0","chai":"^4.1.2","esbuild":"^0.12.22","eslint":"^6.3.0","mocha":"^9.0.0","source-map-support":"^0.5.12","ts-node":"^10.0.0","typedoc":"^0.21.6","typescript":"^4.3.5"},"gitHead":"2f9211e95f8b7342931c0a752c848910cf7b67f1","bugs":{"url":"https://github.com/ancientec/password-policy-js/issues"},"homepage":"https://github.com/ancientec/password-policy-js#readme","_id":"@ancientec/password-policy-js@1.0.1","_nodeVersion":"16.2.0","_npmVersion":"7.13.0","dist":{"integrity":"sha512-b4KhrIts6Fug96blzvmS1DY6XbBB1tmX7yP8jyWtggnxAdju/xhJuZeC2TupXrWWuOZGI8ql15RqC4uEL1kW1w==","shasum":"9900cd7db3fa306be61a7c03a837dd3fe6fa5003","tarball":"https://registry.npmjs.org/@ancientec/password-policy-js/-/password-policy-js-1.0.1.tgz","fileCount":15,"unpackedSize":57176,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhKKqNCRA9TVsSAnZWagAAnvAP/iZmKxfzIVty/ChUTnNz\nHGM5uT4ojjPccLONH5xIITIWXX+dGDjcWD1v5SNLj4g1IvZ0NSdisNYxBxJw\nGUOl8rhS9qY4zoPBeLajypmXZaPUXd3iOEDOZwmC7oT06uAmF6oi26CgPKYb\nWezIXAt5Y8y/7WsgTXDrG6aHyHpWcNuq5zrW5h3Onu93HL9V/OFQQILXJech\nPwb4fsXsI9lvrWoAY7nNH2Ay2OtlZ1HtK9G32St5HRRce5z7hwnb1Vos1h38\nTMiEk34hXR5nVcUo/ne6MPnZG1+dc+WpbvYhFOoORV176JFZGiawr18Y7S9H\n+e/+jxsPKbxQUntvUpvgXzlIqGRz0Td7CjBw4eNJR0vxMYtljMGckP5bTN6j\ntOnezsTqQQzw4w9c7VnhxaMmEWSF1alvxcVbxFyQoBwCF0Tb0/BqOa/BxNZb\niMB9vaGXJC8cqtc5ZSdgL5Y/Vva1ly3WRdEEFmcrn88mzVRXeBfhNndX012e\n+ymnnD7PGL/N+9whLuQqUkjKaK/Hj5E35qs8S4sosK6KK1Br74/7knxI1W53\ntNxyy/bp1Sph28p1g9bEn6a0o/gT6iGl7kPpCnMw3Rv0pa047JeH4JRhuFS3\ne+jhRRXhkpYrN3Fkl+bwZgIRslmpX8S0wqpa2q1NaE3CuAqPTYuKFgRy+Fmo\nTOAO\r\n=Ha1g\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHKjBI2IOGauKREkNd0s8PCyt3r8R+IS3EMUlnA9ocqdAiEAix0z0tIfbTyGCaJhx01wv8vGZabWKtQgoywLQDR063E="}]},"_npmUser":{"name":"ancientec","email":"open@ancientec.com"},"directories":{},"maintainers":[{"name":"ancientec","email":"open@ancientec.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/password-policy-js_1.0.1_1630055053404_0.37277088797410296"},"_hasShrinkwrap":false}},"time":{"created":"2021-08-27T06:15:30.532Z","1.0.0":"2021-08-27T06:15:30.787Z","modified":"2022-04-04T13:57:13.457Z","1.0.1":"2021-08-27T09:04:13.574Z"},"maintainers":[{"name":"ancientec","email":"open@ancientec.com"}],"description":"helper function to generate password policies and validate against password","homepage":"https://github.com/ancientec/password-policy-js#readme","keywords":["password","policy","rules","validation"],"repository":{"type":"git","url":"git+https://github.com/ancientec/password-policy-js.git"},"author":{"name":"Ancientec Co., Ltd."},"bugs":{"url":"https://github.com/ancientec/password-policy-js/issues"},"license":"MIT","readme":"# `password-policy` \n\nJavascript helper function to generate password policies and validate against password, for both server and browser.\n\nPHP Version:\n[https://github.com/ancientec/password-policy ](https://github.com/ancientec/password-policy)\n\nJS Version (for frontend and backend):\n[https://github.com/ancientec/password-policy-js ](https://github.com/ancientec/password-policy-js)\n\n## Features\n- Cache and validate multiple policies by assigning different names\n- Customiziable error strings, multilingual possible\n- Custom error handling\n- Custom validation\n- Detail errors\n- Compatiable php version\n\n## Install\n\n```shell\n> npm install @ancientec/password-policy-js\n```\n## Develop & Unit Test\n\n```shell\n> git clone https://github.com/ancientec/password-policy-js\n> cd password-policy\n> npm install\n> npm run test\n> npm build\n```\n\n## Usage & Example\n\n```html\n<!--quick start in html:-->\n<script src=\"password-policy.min.js\"></script>\n<script>\n    var passwordPolicy = new PasswordPolicy({\"LengthMin\" : 6}, {}, \"policy_admin\");\n    passwordPolicy.isValid(\"password\"); //return true\n    passwordPolicy.validate(\"password\"); //return {}\n</script>\n```\n\n```js\n\nimport {PasswordPolicy} from 'password_policy';\n\nconst policy = {\"LengthMin\" : 6, //minimum length of password\n      \"LengthMax\" : 12, //maximum length of password\n      \"CharDigitMin\" : 1, //minimum number of digits\n      \"CharUpperMin\" : 1,//minimum number of upper case characters\n      \"CharLowerMin\" : 1,//minimum number of lower case characters\n      \"CharSpecial\" : \"~!@#%^&*()-=_+\",//defination of special characters\n      \"CharSpecialMin\" : 1,//minimum number of special characters\n      \"MustContain\" : ['1','a'], //must contain strs, case sensitive\n      \"MustNotContain\" : ['admin','password'],//must not contain strs, case sensitive\n      \"CustomValidate\" : (password) => { return \"\";}, //return error string if false, return \"\" if true\n    };\n\n/**\n * variables:\n * policy : array,\n * errorStrings : array, optional\n * policy_name: string, optional\n*/\nconst passwordPolicy = new PasswordPolicy(policy, {}, \"policy_admin\");\n\n//return false:\npasswordPolicy.isValid(\"password\"); //false\n\n//return true:\npasswordPolicy.isValid(\"Password123!\"); //true\n\n//return empty array if the password is passed:\npasswordPolicy.Validate(\"Password123!\"); // empty {}\n\n//return array of error strings:\npasswordPolicy.Validate(\"\"); \n/* result:\n{\"ERR_LengthMin\" : \"minimum length of 6\",\n        \"ERR_LengthMax\" :  \"maximum length of 12\",\n        \"ERR_CharDigitMin\" : \"at least 1 of digit(s)\",\n        \"ERR_CharUpperMin\" : \"at least 1 of upper case character\",\n        \"ERR_CharLowerMin\" : \"at least 1 of lower case character\",\n        \"ERR_CharSpecial\" : \"at least 1 of special character ~!@#%^&*()-=_+\",\n        \"ERR_MustContain\" : [\"must contain 1\",\"must contain a\"],\n        \"ERR_All\" : [\n              \"maximum length of 12\",\n              \"at least 1 of digit(s)\",\n              \"at least 1 of upper case character\",\n              \"at least 1 of lower case character\",\n              \"at least 1 of special character ~!@#%^&*()-=_+\",\n              \"must contain 1\",\n              \"must contain a\"\n        ]\n}\n*/\n\n```\nThe returned error array can be processed by using string index or by numeric index in ERR_All\n\n## Multiple Policies\n\n```js\n\n//only check minimum length\nconst passwordPolicy = new PasswordPolicy({\"LengthMin\" : 6}, {}, \"policy_admin\");\n\n//create a new instance\nconst passwordPolicyUser = new PasswordPolicy({\"LengthMin\" : 12}, {}, \"policy_user\");\n\n//or use static.method\nPasswordPolicy.registerPolicy({\"LengthMin\" : 32, \"LengthMax\" : 32}, {}, \"policy_api\");\n\n//policy is still policy_admin:\npasswordPolicy.isValid(\"Password123!\");//return true\n\n//change current policy name to policy_user\npasswordPolicy.setPolicyName(\"policy_user\");\n\n//policy_user validate:\npasswordPolicy.isValid(\"Password123!\");//return false\n\n//assign policy name to validate:\npasswordPolicy.isValid(\"Password123!\", \"policy_admin\");//return \n\n\n\n//policy is policy_user\npasswordPolicyUser.isValid(\"Password123!\");//return false\n\n//assign policy name to validate:\npasswordPolicy.isValid(\"Password123!\", \"policy_user\");//return false\n\n//assign policy name to validate:\npasswordPolicy.isValid(\"Password123!\", \"policy_api\");//return false\n\n```\n\n## Customizible Error Strings\n```js\n\nlet errorStrings = PasswordPolicy.getErrorStringsDefault();\n/* default strings:\n\n{\"ERR_LengthMin\" : \"minimum length should be {0}\",\n        \"ERR_LengthMax\" :  \"maximum length should be {0}\",\n        \"ERR_CharDigitMin\" : \"at least {0} of digit(s)\",\n        \"ERR_CharUpperMin\" : \"at least {0} of upper case character\",\n        \"ERR_CharLowerMin\" : \"at least {0} of lower case character\",\n        \"ERR_CharSpecial\" : \"at least {0} of special character {1}\",\n        \"ERR_MustContain\" : \"must contain {0}\",\n        \"ERR_MustNotContain\" : \"must not contain {0}\",\n        \"ERR_NoDefinedPolicies\" : \"Missing defined policies\",\n}\n*/\nerrorStrings[\"ERR_LengthMin\"] = \"Minimum length must be {0}\";\n\nconst passwordPolicy = new PasswordPolicy(\n      {\"LengthMin\" : 6, \"LengthMax\" : 6},errorStrings, \"policy_user\");\n//alertnatively:\npasswordPolicy.setErrorStringsWithName(errorStrings, \"policy_user\");\n\npasswordPolicy.validate(\"\");\n/* result:\n{\n      \"ERR_LengthMin\" : \"minimum length must be 6\",\n      \"ERR_All\" : [\"minimum length must be 6\"]\n}\n*/\n\n```\n\n## Customizible Error String Functions\nIn case if you need to translate error strings dynamically during runtime. Note that all error strings should be covered if you define your own function:\n```js\n\n/*\nerror : string, type of error\nvalues: string[], policy requirement\n*/\nconst ErrorStringFormat = function(error, values) {\n\n      const myLanguageStrings = {\"ERR_LengthMin\" : \"minimum length must be {0}\",\n        \"ERR_LengthMax\" :  \"maximum length must be {0}\",\n        \"ERR_CharDigitMin\" : \"at least {0} of digit(s)\",\n        \"ERR_CharUpperMin\" : \"at least {0} of upper case character\",\n        \"ERR_CharLowerMin\" : \"at least {0} of lower case character\",\n        \"ERR_CharSpecial\" : \"at least {0} of special character {1}\",\n        \"ERR_MustContain\" : \"must contain {0}\",\n        \"ERR_MustNotContain\" : \"must not contain {0}\",\n        \"ERR_NoDefinedPolicies\" : \"Missing defined policies\",\n      };\n      switch(error) {\n            case 'ERR_CharSpecial':\n                return myLanguageStrings[error].replace(\"{0}\",values[0]).replace(\"{1}\",values[1]);\n            case 'ERR_NoDefinedPolicies':\n                return myLanguageStrings[error];\n            default:\n            return myLanguageStrings[error].replace(\"{0}\",values[0]);\n      }\n}\n\nconst policy = {\n      \"LengthMin\" : 6, \n      \"LengthMax\" : 6,\n      \"ErrorStringFormat\" : ErrorStringFormat};\n\nconst passwordPolicy = new PasswordPolicy(policy);\n\npasswordPolicy.validate(\"\");\n/* result:\n{\n      \"ERR_LengthMin\" : \"minimum length must be 6\",\n      \"ERR_All\" : [\"minimum length must be 6\"],\n}\n*/\n\n```\n\n## Custom Validation\nProvide your own validation.\n```js\nconst customValidate = function(password) {\n      //password is not ok:\n      if(password.indexOf('abc') !== 0) {\n            return \"password should prefix abc\";\n      }\n\n      //password is ok:\n      return \"\";\n};\n\nconst passwordPolicy = new PasswordPolicy({\n      \"LengthMin\" : 6,\n      \"CustomValidate\" : customValidate\n});\n\npasswordPolicy.isValid(\"password\"); //return false\n\npasswordPolicy.validate(\"password\");\n/*\nresult:\n{\n      \"ERR_CustomValidate\" : \"password should prefix abc\",\n      \"ERR_All\" : [\"password should prefix abc\"],\n}\n*/\n\npasswordPolicy.isValid(\"abcPassword\"); //return true\npasswordPolicy.validate(\"abcPassword\"); //result: {}\n\n```\n\n##Static Methods\nRegister new policies\n```js\n/*\npolicy: array,\nerrorStrings : array, optional\nname: string, optional\n*/\nPasswordPolicy.registerPolicy(/*policy*/, /*errorStrings*/, /*name*/);\n```\n\nSet error strings\n```js\n/*\nerrorStrings : array,\nname: string, optional\n*/\nPasswordPolicy.setErrorStringsWithName(/*errorStrings*/, /*name*/);\n```\n\nGet All registered policies\n```js\n/*\nreturn array\n*/\nPasswordPolicy.getPolicies();\n```\n\nGet policy\n```js\n/*\nreturn first policy\n*/\nPasswordPolicy.getPolicy();\n\n/*\nreturn  policy by name\n*/\nPasswordPolicy.getPolicy(\"default\");\n```\n\nGet default policy definition\n```js\n/*\nreturn {\"LengthMin\" : 8,\n        \"LengthMax\" : 16,\n        \"CharDigitMin\" : 1,\n        \"CharUpperMin\" : 1,\n        \"CharLowerMin\" : 1,\n        \"CharSpecial\" : \"~!@#%^&*()-=_+\",\n        \"CharSpecialMin\" : 1,\n        \"MustContain\" : [],\n        \"MustNotContain\" : [],\n        }\n*/\nPasswordPolicy.getPolicyDefault();\n```\n\nGet default error strings definition\n```js\n/*\nreturn {\"ERR_LengthMin\" : \"minimum length should be {0}\",\n        \"ERR_LengthMax\" :  \"maximum length should be {0}\",\n        \"ERR_CharDigitMin\" : \"at least {0} of digit(s)\",\n        \"ERR_CharUpperMin\" : \"at least {0} of upper case character\",\n        \"ERR_CharLowerMin\" : \"at least {0} of lower case character\",\n        \"ERR_CharSpecial\" : \"at least {0} of special character {1}\",\n        \"ERR_MustContain\" : \"must contain {0}\",\n        \"ERR_MustNotContain\" : \"must not contain {0}\",\n        \"ERR_NoDefinedPolicies\" : \"Missing defined policies\",\n        };\n*/\nPasswordPolicy.getErrorStringsDefault();\n```\n\n## License\n\nMIT","readmeFilename":"README.md"}