• Resolved kaowinn

    (@kaowinn)


    Hello

    How can I please change the “strong password” in learnpress?
    I can see into the plugin code at: “learnpress>inc>class-lp-forms-handler.php” the following class method: “register_validate_field”.

    This method forces the user to use strong password. And this method is used as filter into the “process_register” method :

    add_filter( ‘learn-press/register-validate-field’, array(__CLASS__, ‘register_validate_field’), 10, 3 );

    How can I please change this filter? Because I need to allow my user to use more open password, many people do not subscribe to my service because their password doesn’t match the learnpress policy and I do not have to force them.

    I need to remove these rule:
    – Password must include at least one of these characters ~!@#$%^&*() !
    – Password must include at least one capitalized letter!
    – Password can not have spacing!

    Thank you so much,
    Kelvin

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kaowinn

    (@kaowinn)

    Hello again ??

    I found a way. I created the following code into a custom plugin :

    /**
     * fr : Mise à jour de la politique de validation du MDP avec learnpress
     * en : Update password policy on learnpress
     */
    add_filter( 'learn-press/register-validate-field', 'oc_register_validate_field', 15, 3 );
    function oc_register_validate_field( $name, $field, $value ) {
        $validate = ! ! $value;
    
        /*error_log('oc_register_validate_field reg_password ' . json_encode([
            'name' => $name,
            'field' => $field,
            'field-id' => $field['id'],
            'value' => $value,
        ]));/**/
        if ( $validate && $field['id'] === 'reg_password' ) {
            try {
                if ( strlen( $value ) < 8 ) {
                    throw new Exception( __( 'Password is too short!', 'learnpress' ), 100 );
                }
    
                /* if ( preg_match( '#\s+#', $value ) ) {
                    throw new Exception( __( 'Password can not have spacing!', 'learnpress' ), 110 );
                }/**/
    
                if ( ! preg_match( "#[a-zA-Z]+#", $value ) ) {
                    throw new Exception( __( 'Password must include at least one letter!', 'learnpress' ), 120 );
                }/**/
    
                /* if ( ! preg_match( "#[A-Z]+#", $value ) ) {
                    throw new Exception( __( 'Password must include at least one capitalized letter!', 'learnpress' ), 125 );
                }/**/
    
                if ( ! preg_match( "#[0-9]+#", $value ) ) {
                    throw new Exception( __( 'Password must include at least one number!', 'learnpress' ), 125 );
                }/**/
    
                /* if ( ! preg_match( '#[~!@\#$%^&*()]#', $value ) ) {
                    throw new Exception( __( 'Password must include at least one of these characters ~!@#$%^&*() !', 'learnpress' ), 125 );
                }
                /**/
            } catch ( Exception $ex ) {
                $validate = new WP_Error( $ex->getCode(), $ex->getMessage() );
            }
        }
    
        return $validate;
    }
    /**/

    Hope it cans help other people. It works with Learnpress (Version 3.2.7.9).
    But, be careful, I voluntary decrease to minimum requirement of my user password because I do not host any private data and I prefer to build the most user friend experience. Please think twice before use this code.

    Have you seen this, @thimpress?

    Any news on this topic?

    Best.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change password policy in LearnPress’ is closed to new replies.