Ignore:
Timestamp:
Oct 23, 2013, 6:04:53 PM (10 years ago)
Author:
Eric
Message:

r25092 merged from trunk to branch 2.51 :
Bug 1109 fixed - Password enforcement features have been removed from UAM and set in a new dedicated plugin : Password Policy

Language files cleanup

Bug 2984 fixed - Display issue in Miscellaneous options
Bug 2986 fixed - Status for unvalidated users can not be "Guest" and is forced to "-------"
Bug 2987 fixed - New registered users have to follow a link on confirmation page before log in

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/UserAdvManager/branches/2.51/include/functions.inc.php

    r25062 r25093  
    223223    load_language('plugin.lang', UAM_PATH);
    224224
    225     $PasswordCheck = 0;
    226 
    227225    $conf_UAM = unserialize($conf['UserAdvManager']);
    228 
    229     // Password enforcement control
    230     // ----------------------------
    231     if (isset($conf_UAM['PASSWORDENF']) and $conf_UAM['PASSWORDENF'] == 'true' and !empty($conf_UAM['PASSWORD_SCORE']))
    232     {
    233       if (!empty($user['password']) and !is_admin())
    234       {
    235         $PasswordCheck = testpassword($user['password']);
    236  
    237         if ($PasswordCheck < $conf_UAM['PASSWORD_SCORE'])
    238         {
    239           $message = get_l10n_args('UAM_reg_err_login4_%s', $PasswordCheck);
    240           $lang['reg_err_pass'] = l10n_args($message).$conf_UAM['PASSWORD_SCORE'];
    241           array_push($errors, $lang['reg_err_pass']);
    242         }
    243       }
    244       else if (!empty($user['password']) and is_admin() and isset($conf_UAM['ADMINPASSWENF']) and $conf_UAM['ADMINPASSWENF'] == 'true')
    245       {
    246         $PasswordCheck = testpassword($user['password']);
    247  
    248         if ($PasswordCheck < $conf_UAM['PASSWORD_SCORE'])
    249         {
    250           $message = get_l10n_args('UAM_reg_err_login4_%s', $PasswordCheck);
    251           $lang['reg_err_pass'] = l10n_args($message).$conf_UAM['PASSWORD_SCORE'];
    252           array_push($errors, $lang['reg_err_pass']);
    253         }
    254       }
    255     }
    256226
    257227    // Username without forbidden keys
     
    302272  }
    303273
    304   // Special message display for password reset
    305   // ------------------------------------------
    306   if ((isset($conf_UAM['PWDRESET']) and $conf_UAM['PWDRESET'] == 'true'))
    307   {
    308     if (UAM_check_pwgreset($user['id']))
    309     {
    310       $template->append('errors', l10n('UAM_Password_Reset_Msg'));
    311     }
    312   }
    313 
    314274  // Controls on profile page submission
    315275  // -----------------------------------
     
    327287    }
    328288
    329     // Password reset control
    330     // ----------------------
    331     if (isset($conf_UAM['PWDRESET']) and $conf_UAM['PWDRESET'] == 'true' and UAM_check_pwgreset($user['id']))
    332     {
    333       // if password not changed then pwdreset field = true else pwdreset field = false
    334       // ------------------------------------------------------------------------------
    335       if (!empty($_POST['use_new_pwd']))
    336       {
    337         $query = '
    338 UPDATE '.USERS_TABLE.'
    339 SET UAM_pwdreset = "false"
    340 WHERE id = '.$user['id'].'
    341 LIMIT 1
    342 ;';
    343         pwg_query($query);
    344       }
    345     }
    346 
    347289    $typemail = 3; // Only information email send to user on user profile update if checked
    348290
     
    350292    {
    351293      $typemail = 2; // Confirmation email on user profile update - With information email
    352 
    353       // Password enforcement control
    354       // ----------------------------
    355       if (isset($conf_UAM['PASSWORDENF']) and $conf_UAM['PASSWORDENF'] == 'true' and !empty($conf_UAM['PASSWORD_SCORE']))
    356       {
    357         $PasswordCheck = testpassword($_POST['use_new_pwd']);
    358 
    359         if ($PasswordCheck < $conf_UAM['PASSWORD_SCORE'])
    360         {
    361           $message = get_l10n_args('UAM_reg_err_login4_%s', $PasswordCheck);
    362           $template->append('errors', l10n_args($message).$conf_UAM['PASSWORD_SCORE']);
    363           unset($_POST['use_new_pwd']);
    364           unset($_POST['validate']);
    365         }
    366       }
    367294    }
    368295
     
    453380        or (!is_admin() and !is_webmaster()))
    454381  {
     382
    455383    // Performing redirection to profile page on first login
    456384    // -----------------------------------------------------
     
    469397        if (!UAM_check_profile($user['id'], $user_idsOK))
    470398          redirect(PHPWG_ROOT_PATH.'profile.php');
    471       }
    472     }
    473 
    474     // Performing redirection to profile page for password reset
    475     // ---------------------------------------------------------
    476     if ((isset($conf_UAM['PWDRESET']) and $conf_UAM['PWDRESET'] == 'true'))
    477     {
    478       $query ='
    479 SELECT user_id, status
    480 FROM '.USER_INFOS_TABLE.'
    481 WHERE user_id = '.$user['id'].'
    482 ;';
    483       $data = pwg_db_fetch_assoc(pwg_query($query));
    484 
    485       if ($data['status'] <> "webmaster" and $data['status'] <> "generic") // Exclusion of specific accounts
    486       {
    487         if (UAM_check_pwgreset($user['id']))
    488         {
    489           redirect(PHPWG_ROOT_PATH.'profile.php');
    490         }
    491399      }
    492400    }
     
    1062970        if (function_exists('get_user_language_desc'))
    1063971        {
    1064           $custom_text = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail['CONFIRMMAIL_CUSTOM_TXT1']));
     972          $login_link = '<a href="'.get_gallery_home_url().'" style="font-weight: bold;text-align: center;color: #FF0000;text-transform: uppercase;">'.l10n('UAM_Follow this link to access the gallery').'</a>';
     973          $custom_text = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail['CONFIRMMAIL_CUSTOM_TXT1']))."<br/><br/>".$login_link;
    1065974        }
    1066975        else
     
    1070979        $page['infos'][]=$custom_text;
    1071980      }
    1072     } 
     981    }
    1073982    else
    1074983    {
     
    21402049  {
    21412050    $query = '
    2142 INSERT INTO '.USER_INFOS_TABLE.'
    2143   (user_id, level)
    2144 VALUES
    2145   ('.$user_id.', "'.$conf_UAM['NO_VALID_LEVEL'].'")
     2051UPDATE '.USER_INFOS_TABLE.'
     2052SET level = "'.$conf_UAM['NO_VALID_LEVEL'].'"
     2053WHERE user_id = '.$user_id.'
    21462054;';
    21472055
    21482056    pwg_query($query);
     2057
     2058//    $query = '
     2059//INSERT INTO '.USER_INFOS_TABLE.'
     2060//  (user_id, level)
     2061//VALUES
     2062//  ('.$user_id.', "'.$conf_UAM['NO_VALID_LEVEL'].'")
     2063//;';
     2064//
     2065//    pwg_query($query);
    21492066  }
    21502067}
     
    30162933
    30172934/**
    3018  * Returns a password's score for password complexity check
    3019  *
    3020  * @param : password filled by user
    3021  *
    3022  * @return : Score calculation
    3023  *
    3024  * Thanx to MathieuGut from http://m-gut.developpez.com
    3025  */
    3026 function testpassword($password) // $password given by user
    3027 {
    3028 
    3029   // Variables initiation
    3030   // --------------------
    3031   $points = 0;
    3032   $point_lowercase = 0;
    3033   $point_uppercase = 0;
    3034   $point_numbers = 0;
    3035   $point_characters = 0;
    3036 
    3037   // Getting password lengh
    3038   // ----------------------
    3039   $length = strlen($password);
    3040 
    3041   // Loop to read password characters
    3042   for($i = 0; $i < $length; $i++)
    3043   {
    3044     // Select each letters
    3045     // $i is 0 at first turn
    3046     // ---------------------
    3047     $letters = $password[$i];
    3048 
    3049     if ($letters>='a' && $letters<='z')
    3050     {
    3051       // Adding 1 point to score for a lowercase
    3052       // ---------------------------------------
    3053                                 $points = $points + 1;
    3054 
    3055       // Adding bonus points for lowercase
    3056       // ---------------------------------
    3057                   $point_lowercase = 1;
    3058     }
    3059     else if ($letters>='A' && $letters <='Z')
    3060     {
    3061       // Adding 2 points to score for uppercase
    3062       // --------------------------------------
    3063       $points = $points + 2;
    3064 
    3065       // Adding bonus points for uppercase
    3066       // ---------------------------------
    3067       $point_uppercase = 2;
    3068     }
    3069     else if ($letters>='0' && $letters<='9')
    3070     {
    3071       // Adding 3 points to score for numbers
    3072       // ------------------------------------
    3073       $points = $points + 3;
    3074 
    3075       // Adding bonus points for numbers
    3076       // -------------------------------
    3077       $point_numbers = 3;
    3078     }
    3079     else
    3080     {
    3081       // Adding 5 points to score for special characters
    3082       // -----------------------------------------------
    3083       $points = $points + 5;
    3084                
    3085       // Adding bonus points for special characters
    3086       // ------------------------------------------
    3087       $point_characters = 5;
    3088     }
    3089   }
    3090 
    3091   // Calculating the coefficient points/length
    3092   // -----------------------------------------
    3093   $step1 = $points / $length;
    3094 
    3095   // Calculation of the diversity of character types...
    3096   // --------------------------------------------------
    3097   $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters;
    3098 
    3099   // Multiplying the coefficient of diversity with that of the length
    3100   // ----------------------------------------------------------------
    3101   $score = $step1 * $step2;
    3102 
    3103   // Multiplying the result by the length of the string
    3104   // --------------------------------------------------
    3105   $finalscore = $score * $length;
    3106 
    3107   return $finalscore;
    3108 }
    3109 
    3110 
    3111 /**
    31122935 * UAM_check_profile - Thx to LucMorizur
    31132936 * checks if a user id is registered as having already
     
    31402963  }
    31412964  return $v;
    3142 }
    3143 
    3144 
    3145 /**
    3146  * UAM_check_pwdreset
    3147  * checks if a user id is registered as having already
    3148  * changed his password.
    3149  *
    3150  * @uid        : the user id
    3151  *
    3152  * @returns    : true or false whether the users has already changed his password
    3153  *
    3154  */
    3155 function UAM_check_pwgreset($uid)
    3156 {
    3157   $query = '
    3158 SELECT UAM_pwdreset
    3159 FROM '.USERS_TABLE.'
    3160 WHERE id='.$uid.'
    3161 ;';
    3162 
    3163   $result = pwg_db_fetch_assoc(pwg_query($query));
    3164 
    3165   if($result['UAM_pwdreset'] == 'true')
    3166   {
    3167     return true;
    3168   }
    3169   else return false;
    31702965}
    31712966
     
    32303025
    32313026  pwg_query($query);
    3232 }
    3233 
    3234 
    3235 /**
    3236  * UAM_Set_PwdReset
    3237  * Action in user_list to set a password reset for a user
    3238  */
    3239 function UAM_Set_PwdReset($uid)
    3240 {
    3241   $query ='
    3242 UPDATE '.USERS_TABLE.'
    3243 SET UAM_pwdreset = "true"
    3244 WHERE id = '.$uid.'
    3245 LIMIT 1
    3246 ;';
    3247 
    3248   pwg_query($query);
    3249 }
    3250 
    3251 
    3252 /**
    3253  * UAM_loc_visible_user_list
    3254  * Adds a new feature in user_list to allow password reset for selected users by admin
    3255  *
    3256  */
    3257 function UAM_loc_visible_user_list($visible_user_list)
    3258 {
    3259   global $template;
    3260 
    3261   $template->append('plugin_user_list_column_titles', l10n('UAM_PwdReset'));
    3262 
    3263   $user_ids = array();
    3264 
    3265   foreach ($visible_user_list as $i => $user)
    3266   {
    3267     $user_ids[$i] = $user['id'];
    3268   }
    3269 
    3270   $user_nums = array_flip($user_ids);
    3271 
    3272   // Query to get information in database
    3273   // ------------------------------------
    3274   if (!empty($user_ids))
    3275   {
    3276     $query = '
    3277 SELECT DISTINCT id, UAM_pwdreset
    3278   FROM '.USERS_TABLE.'
    3279   WHERE id IN ('.implode(',', $user_ids).')
    3280 ;';
    3281     $result = pwg_query($query);
    3282 
    3283     while ($row = pwg_db_fetch_assoc($result))
    3284     {
    3285       if ($row['UAM_pwdreset'] == 'false')
    3286       {
    3287         $pwdreset = l10n('UAM_PwdReset_Done');
    3288       }
    3289       else if ($row['UAM_pwdreset'] == 'true')
    3290       {
    3291         $pwdreset = l10n('UAM_PwdReset_Todo');
    3292       }
    3293       else $pwdreset = l10n('UAM_PwdReset_NA');
    3294 
    3295                   $visible_user_list[$user_nums[$row['id']]]['plugin_columns'][] = $pwdreset; // Shows users password state in user_list
    3296     }
    3297   }
    3298   return $visible_user_list;
    32993027}
    33003028
Note: See TracChangeset for help on using the changeset viewer.