1

I am looking to check the strength of a password using the WordPress API. I cant seem to find a function that allows me to do so. The code be

<?php
    add_action( 'custom_api_init', function () {
        // Check Password Strength
        register_rest_route( 
            'custom/v2', 
            '/strength/', 
            array( 
                'methods' => 'POST', 
                'callback' => 'custom_api_strength'
            ) 
        );
    }

    function custom_api_strength($data){
        if(
            isset(
                $data['password'],
                $data['username'],
                $data['email'],
                $data['fname'],
                $data['lname']
            )
        ){

            // Check Password Strength


            return array('result'=>$strength);
        }else{ return array( 'result'=>'0'); }
    }
?>
2

WordPress uses the zxcvbn javascript library by Dropbox, to estimate the password strength.

We can see the implementation in:

with:

strength = wp.passwordStrength.meter( 
    pass1, 
    wp.passwordStrength.userInputBlacklist(),
    pass1 
);

As far as I know there's no explicit PHP WordPress API for estimating the password strength, but zxcvbn has been ported to a PHP library here, but I'm don't know the current state of that library.

  • ps: here I played with a patch to add the password strength info to the email sent to admin when a user changes the password. – birgire Jun 23 '18 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.