{"id":13622892,"url":"https://github.com/ircmaxell/password-policy","last_synced_at":"2025-04-15T10:31:55.947Z","repository":{"id":6518896,"uuid":"7759787","full_name":"ircmaxell/password-policy","owner":"ircmaxell","description":"A password policy enforcer for PHP and JavaScript","archived":false,"fork":false,"pushed_at":"2016-09-07T17:38:39.000Z","size":32,"stargazers_count":77,"open_issues_count":8,"forks_count":20,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-08-01T21:55:24.575Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ircmaxell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-22T19:44:06.000Z","updated_at":"2023-12-02T17:55:51.000Z","dependencies_parsed_at":"2022-09-08T02:36:13.230Z","dependency_job_id":null,"html_url":"https://github.com/ircmaxell/password-policy","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2Fpassword-policy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2Fpassword-policy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2Fpassword-policy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2Fpassword-policy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ircmaxell","download_url":"https://codeload.github.com/ircmaxell/password-policy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223668515,"owners_count":17182942,"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":[],"created_at":"2024-08-01T21:01:25.400Z","updated_at":"2024-11-08T10:31:21.066Z","avatar_url":"https://github.com/ircmaxell.png","language":"PHP","readme":"PasswordPolicy\n==============\n\nA tool for checking and creating password policies in PHP and JS.\n\n## Installation\n\nUse composer to setup an autoloader\n\n    php composer.phar install\n\nRequire the composer autoload file:\n\n    require_once 'vendor/autoload.php';\n\n## Usage:\n\nTo use, first instantiate the core policy object:\n\n    $policy = new \\PasswordPolicy\\Policy;\n\nThen, add rules:\n\n    $policy-\u003econtains('lowercase', $policy-\u003eatLeast(2));\n\n### Supported rule helper methods are:\n\n * `contains($class, $constraint = null, $description = '')`: Checks to see if a password contains a class of chars\n \n    Supported Short-Cut classes:\n\n    * `letter` - `a-zA-Z`\n    * `lowercase` - `a-z`\n    * `uppercase` - `A-Z`\n    * `digit` - `0-9`\n    * `symbol` - `^a-zA-Z0-9` (in other words, non-alpha-numeric)\n    * `null` - `\\0`\n    * `alnum` - `a-zA-Z0-9`\n\n    The second param is a constraint (optional)\n\n * `length($constraint)`: Checks the length of the password matches a constraint\n\n * `endsWith($class, $description = '')`: Checks to see if the password ends with a character class.\n\n * `startsWith($class, $description = '')`: Checks to see if the password starts with a character class.\n\n * `notMatch($regex, $description)`: Checks if the password does not match a regex.\n\n * `match($regex, $description)`: Checks if the password matches the regex.\n\n### Supported Constraints:\n\nThe policy also has short-cut helpers for creating constraints:\n\n * `atLeast($n)`: At least the param matches\n\n    Equivalent to `between($n, PHP_INT_MAX)`\n\n * `atMost($n)`: At most the param matches\n\n    Equivalent to `between(0, $n)`\n\n * `between($min, $max)`: Between $min and $max number of matches\n\n * `never()`: No matches\n     \n    Equivalent to `between(0, 0)`\n\n## Testing the policy\n\nOnce you setup the policy, you can then test it in PHP using the `test($password)` method.\n\n    $result = $policy-\u003etest($password);\n\nThe result return is a stdclass object with two members, result and messages.\n\n * `$result-\u003eresult` - A boolean if the password is valid.\n\n * `$result-\u003emessages` - An array of messages\n\nEach message is an object of two members:\n\n * `$message-\u003eresult` - A boolean indicating if the rule passed\n\n * `$message-\u003emessage` - A textual description of the rule\n\n## Using JavaScript\n\nOnce you've built the policy, you can call `toJavaScript()` to generate a JS anonymous function for injecting into JS code.\n\n    $js = $policy-\u003etoJavaScript();\n    echo \"var policy = $js;\";\n\nThen, the policy object in JS is basically a wrapper for `$policy-\u003etest($password)`, and behaves the same (same return values).\n\n    var result = policy(password);\n    if (!result.result) {\n        /* Process Messages To Display Failure To User */\n    }\n\nOne note for the JavaScript, any regular expressions that you write need to be deliminated by `/` and be valid JS regexes (no PREG specific functionality is allowed).\n\n","funding_links":[],"categories":["密码","目录","Table of Contents","密码 Passwords","PHP","Security","Passwords","密码( Passwords )"],"sub_categories":["密码 Passwords","Passwords"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fircmaxell%2Fpassword-policy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fircmaxell%2Fpassword-policy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fircmaxell%2Fpassword-policy/lists"}