Skip to content

Commit

Permalink
Password Checker: Initial Skeleton (#18700)
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
  • Loading branch information
briancolinger and anomiex committed Mar 12, 2021
1 parent d001afc commit 67c4391
Show file tree
Hide file tree
Showing 11 changed files with 1,612 additions and 0 deletions.
8 changes: 8 additions & 0 deletions projects/packages/password-checker/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Files not needed to be distributed in the package.
.gitattributes export-ignore
.github/ export-ignore
phpunit.xml.dist export-ignore
tests/ export-ignore

# Files not needed in the production build.
/changelog/** production-exclude
1 change: 1 addition & 0 deletions projects/packages/password-checker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wordpress
7 changes: 7 additions & 0 deletions projects/packages/password-checker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

39 changes: 39 additions & 0 deletions projects/packages/password-checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Password Checker

Password Checker package.

### Usage

Add a new test:

```php
$tests = array(
'preg_match' => array(
'no_backslashes' => array(
'pattern' => '/^[^\\\\]*$/u',
'error' => __( 'Passwords may not contain the character "\".', 'jetpack' ),
'required' => true,
'fail_immediately' => true,
),
),
'compare_to_list' => array(
'not_a_common_password' => array(
'list_callback' => 'get_common_passwords',
'compare_callback' => 'negative_in_array',
'error' => __( 'This is a very common password. Choose something that will be harder for others to guess.', 'jetpack' ),
'required' => true,
),
)
);
$tests = apply_filters( 'password_checker_tests', $tests );
```

Test a password:

```php
use Automattic\Jetpack\Password_Checker;

$user = new WP_User( 1 );
$password_checker = new Password_Checker( $user );
$password_checker->test( '123', true );
```
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: added

Initial release.
51 changes: 51 additions & 0 deletions projects/packages/password-checker/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "automattic/jetpack-password-checker",
"description": "Password Checker.",
"type": "library",
"license": "GPL-2.0-or-later",
"require": {},
"require-dev": {
"automattic/jetpack-changelogger": "1.1.x-dev",
"automattic/wordbless": "@dev",
"yoast/phpunit-polyfills": "0.2.0"
},
"autoload": {
"classmap": [
"src/"
]
},
"scripts": {
"phpunit": [
"@composer install",
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"@composer install",
"phpdbg -d memory_limit=2048M -d max_execution_time=900 -qrr ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
],
"post-update-cmd": "php -r \"copy('vendor/automattic/wordbless/src/dbless-wpdb.php', 'wordpress/wp-content/db.php');\""
},
"repositories": [
{
"type": "path",
"url": "../*",
"options": {
"monorepo": true
}
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"mirror-repo": "Automattic/jetpack-password-checker",
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-password-checker/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-master": "0.1.x-dev"
}
}
}
17 changes: 17 additions & 0 deletions projects/packages/password-checker/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<phpunit bootstrap="tests/php/bootstrap.php" backupGlobals="false" colors="true">
<testsuites>
<testsuite name="main">
<directory prefix="test" suffix=".php">tests/php</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">.</directory>
<exclude>
<directory suffix=".php">tests</directory>
<directory suffix=".php">vendor</directory>
<directory suffix=".php">views</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
Loading

0 comments on commit 67c4391

Please sign in to comment.