Skip to:
Content
Pages
Categories
Search
Top
Bottom

Plugin: BuddyPress Strong Username And Password

  • @livingflame

    Participant

    In your Plugin Directory create a folder and a .php file with this name: bp-strong-username-password

    CODE:

    <?php
    /*
    Plugin Name: BP strong username and password
    Description: Force the new registered in BuddyPress to use strong username and password.
    Version: 1.0
    Author: Anonymous
    */
    
    add_action( 'plugins_loaded', 'plugin_load_textdomain' );
    function plugin_load_textdomain() {
      load_plugin_textdomain( 'bp-strong-username-password', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 
    }
    
    // Force Strong Username
    function strong_username() {
     global $bp;
    
     if ( !empty( $_POST['signup_username'] ) )
       if ( !valid_username( $_POST['signup_username'] ) ){
        $bp->signup->errors['signup_username'] = __( 'Your username is not strong enough. Use uppercase, lowercase and numbers', 'bp-strong-username-password', 'buddypress' );
       }
     }
     add_action( 'bp_signup_validate', 'strong_username');
    
     function valid_username($candidate) {
       $r1='/[A-Z]/';  //Uppercase 
       $r2='/[a-z]/';  //lowercase
       $r3='/[0-9]/';  //numbers
    
       if(preg_match_all($r1,$candidate, $o)<1) return FALSE;
       if(preg_match_all($r2,$candidate, $o)<1) return FALSE;
       if(preg_match_all($r3,$candidate, $o)<1) return FALSE;
       if(strlen($candidate)<8) return FALSE;
    
       return TRUE;
    }
    
    // Force Strong Password
    function strong_validation() {
     global $bp;
    
     if ( !empty( $_POST['signup_password'] ) )
       if ( !valid_pass( $_POST['signup_password'] ) ){
        $bp->signup->errors['signup_password'] = __( 'Your password is not strong enough. Use uppercase, lowercase, numbers and special characters', 'bp-strong-username-password', 'buddypress' );
       }
     }
     add_action( 'bp_signup_validate', 'strong_validation');
    
     function valid_pass($candidate) {
       $r1='/[A-Z]/';  //Uppercase
       $r2='/[a-z]/';  //lowercase
       $r3='/[!@#$%^&*()-_=+{};:,?<.>]/';  // whatever you mean by special char
       $r4='/[0-9]/';  //numbers
    
       if(preg_match_all($r1,$candidate, $o)<1) return FALSE;
       if(preg_match_all($r2,$candidate, $o)<1) return FALSE;
       if(preg_match_all($r3,$candidate, $o)<1) return FALSE;
       if(preg_match_all($r4,$candidate, $o)<1) return FALSE;
       if(strlen($candidate)<8) return FALSE;
    
       return TRUE;
    }

    —————-

    For Translation: In your plugin dir, languages folder, create this file: bp-strong-username-password-es_ES.mo with this:

    Þ•<\\K]\©H©O]ùuW]ÍForce the new registered in BuddyPress to use strong username and password.Your password is not strong enough. Use uppercase, lowercase, numbers and special charactersYour username is not strong enough. Use uppercase, lowercase and numbersProject-Id-Version: BP strong username and password
    Report-Msgid-Bugs-To: 
    POT-Creation-Date: 2017-07-15 19:42+0000
    PO-Revision-Date: 2017-07-15 19:47+0000
    Last-Translator: Anonymous 
    Language-Team: Spanish
    Language: es
    Plural-Forms: nplurals=2; plural=n != 1
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    X-Generator: Loco - https://localise.biz/Forzar a los nuevos registrados en BuddyPress a usar nombre de usuario y contraseña fuertes.Su nombre contraseña no es lo suficientemente fuerte. Use mayúsculas, minúsculas, números y caracteres especialesSu nombre de usuario no es lo suficientemente fuerte. Use mayúsculas, minúsculas y números

    And this file: bp-strong-username-password-es_ES.po with this:

    msgid ""
    msgstr ""
    "Project-Id-Version: BP strong username and password\n"
    "Report-Msgid-Bugs-To: \n"
    "POT-Creation-Date: 2017-07-15 19:42+0000\n"
    "PO-Revision-Date: 2017-07-15 19:47+0000\n"
    "Last-Translator: Anonymous \n"
    "Language-Team: Spanish\n"
    "Language: es\n"
    "Plural-Forms: nplurals=2; plural=n != 1\n"
    "MIME-Version: 1.0\n"
    "Content-Type: text/plain; charset=UTF-8\n"
    "Content-Transfer-Encoding: 8bit\n"
    "X-Generator: Loco - https://localise.biz/"
    
    #: bp-strong-username-password.php:17
    msgid ""
    "Your username is not strong enough. Use uppercase, lowercase and numbers"
    msgstr ""
    "Tu nombre de usuario no es lo suficientemente fuerte. Use mayúsculas, "
    "minúsculas y números"
    
    #: bp-strong-username-password.php:41
    msgid ""
    "Your password is not strong enough. Use uppercase, lowercase, numbers and "
    "special characters"
    msgstr ""
    "Tu contraseña no es lo suficientemente fuerte. Use mayúsculas, "
    "minúsculas, números y caracteres especiales"
    
    #. Description of the plugin
    msgid ""
    "Force the new registered in BuddyPress to use strong username and password."
    msgstr ""
    "Forzar a los nuevos registrados en BuddyPress a usar nombre de usuario y "
    "contraseña fuertes."
Viewing 3 replies - 1 through 3 (of 3 total)
  • @livingflame

    Participant

    If you have problem with Translation, Use the plugin Loco Translate to fix.

    @livingflame

    Participant

    Extra CODE if you want. Put it in your functions.php:

    // Restricted Email Domains. Acept only valid email domains
    add_option('limited_email_domains', array('yahoo.com', 'outlook.com', 'hotmail.com', 'gmail.com', 'aol.com', 'mail.com'));

    @livingflame

    Participant

    Correction:

    <?php
    /*
    Plugin Name: BP strong username and password
    Description: Force the new registered in BuddyPress to use strong username and password.
    Version: 1.0
    Author: Anonymous
    */
    
    add_action( 'plugins_loaded', 'plugin_load_textdomain' );
    function plugin_load_textdomain() {
      load_plugin_textdomain( 'bp-strong-username-password', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); 
    }
    
    // Force Strong Username
    function strong_username() {
     global $bp;
    
     if ( !empty( $_POST['signup_username'] ) )
       if ( !valid_username( $_POST['signup_username'] ) ){
        $bp->signup->errors['signup_username'] = __( 'Your username is too weak or short. Please, use uppercase, lowercase and numbers. Minimum 8 chars.', 'bp-strong-username-password', 'buddypress' );
       }
     }
     add_action( 'bp_signup_validate', 'strong_username');
    
     function valid_username($candidate) {
       $r1='/[A-Z]/';  //Uppercase 
       $r2='/[a-z]/';  //lowercase
       $r3='/[0-9]/';  //numbers
    
       if(preg_match_all($r1,$candidate, $o)<1) return FALSE;
       if(preg_match_all($r2,$candidate, $o)<1) return FALSE;
       if(preg_match_all($r3,$candidate, $o)<1) return FALSE;
       if(strlen($candidate)<8) return FALSE;
    
       return TRUE;
    }
    
    // Force Strong Password
    function strong_validation() {
     global $bp;
    
     if ( !empty( $_POST['signup_password'] ) )
       if ( !valid_pass( $_POST['signup_password'] ) ){
        $bp->signup->errors['signup_password'] = __( 'Your password is weak or too short. Please, use uppercase, lowercase, numbers and special characters. Minimum 8 chars.', 'bp-strong-username-password', 'buddypress' );
       }
     }
     add_action( 'bp_signup_validate', 'strong_validation');
    
     function valid_pass($candidate) {
       $r1='/[A-Z]/';  //Uppercase
       $r2='/[a-z]/';  //lowercase
       $r3='/[!@#$%^&*()-_=+{};:,?<.>]/';  // whatever you mean by special char
       $r4='/[0-9]/';  //numbers
    
       if(preg_match_all($r1,$candidate, $o)<1) return FALSE;
       if(preg_match_all($r2,$candidate, $o)<1) return FALSE;
       if(preg_match_all($r3,$candidate, $o)<1) return FALSE;
       if(preg_match_all($r4,$candidate, $o)<1) return FALSE;
       if(strlen($candidate)<8) return FALSE;
    
       return TRUE;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.