automattic/jetpack-password-checker

Password Checker.

Installs: 133 431

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 1

Type:jetpack-library

v0.2.9 2022-12-02 19:01 UTC

README

Password Checker package.

Usage

Add a new test:

$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:

use Automattic\Jetpack\Password_Checker;

$user = new WP_User( 1 );
$password_checker = new Password_Checker( $user );
$password_checker->test( '123', true );