/** * This function returns a string automatically generated * based on the criteria defined in the array $criteria in config.php */ function password_generate() { global $config; $no_use_similiar = !$config->GetValue('password', 'use_similar'); $lowercase = $config->GetValue('password', 'lowercase'); $uppercase = $config->GetValue('password', 'uppercase'); $digits = $config->GetValue('password', 'numbers'); $punctuation = $config->GetValue('password', 'punctuation'); $length = $config->GetValue('password', 'length'); $outarray = array(); if ($no_use_similiar) { $raw_lower = "a b c d e f g h k m n p q r s t u v w x y z"; $raw_numbers = "2 3 4 5 6 7 8 9"; $raw_punc = "# \$ % ^ & * ( ) _ - + = . , [ ] { } :"; } else { $raw_lower = "a b c d e f g h i j k l m n o p q r s t u v w x y z"; $raw_numbers = "1 2 3 4 5 6 7 8 9 0"; $raw_punc = "# \$ % ^ & * ( ) _ - + = . , [ ] { } : |"; } $llower = explode(" ", $raw_lower); shuffle($llower); $lupper = explode(" ", strtoupper($raw_lower)); shuffle($lupper); $numbers = explode(" ", $raw_numbers); shuffle($numbers); $punc = explode(" ", $raw_punc); shuffle($punc); if ($lowercase > 0) { $outarray = array_merge($outarray, a_array_rand($llower, $lowercase)); } if ($uppercase > 0) { $outarray = array_merge($outarray, a_array_rand($lupper, $uppercase)); } if ($digits > 0) { $outarray = array_merge($outarray, a_array_rand($numbers, $digits)); } if ($punctuation > 0) { $outarray = array_merge($outarray, a_array_rand($punc, $punctuation)); } $num_spec = $lowercase + $uppercase + $digits + $punctuation; if ($num_spec < $length) { $leftover = array(); if ($lowercase > 0) { $leftover = array_merge($leftover, $llower); } if ($uppercase > 0) { $leftover = array_merge($leftover, $lupper); } if ($digits > 0) { $leftover = array_merge($leftover, $numbers); } if ($punctuation > 0) { $leftover = array_merge($leftover, $punc); } if (count($leftover) == 0) { $leftover = array_merge($leftover, $llower, $lupper, $numbers, $punc); } shuffle($leftover); $outarray = array_merge($outarray, a_array_rand($leftover, $criteria['num'] - $num_spec)); } shuffle($outarray); $return = implode('', $outarray); if (DEBUG_ENABLED) { debug_log('password_generate(): Entered with (), Returning (%s)', 1, $return); } return $return; }
/** * This function returns a string automatically generated * based on the criteria defined in the array $criteria in config.php */ function password_generate() { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); } $no_use_similiar = !$_SESSION[APPCONFIG]->getValue('password', 'use_similar'); $lowercase = $_SESSION[APPCONFIG]->getValue('password', 'lowercase'); $uppercase = $_SESSION[APPCONFIG]->getValue('password', 'uppercase'); $digits = $_SESSION[APPCONFIG]->getValue('password', 'numbers'); $punctuation = $_SESSION[APPCONFIG]->getValue('password', 'punctuation'); $length = $_SESSION[APPCONFIG]->getValue('password', 'length'); $outarray = array(); if ($no_use_similiar) { $raw_lower = 'a b c d e f g h k m n p q r s t u v w x y z'; $raw_numbers = '2 3 4 5 6 7 8 9'; $raw_punc = '# $ % ^ & * ( ) _ - + = . , [ ] { } :'; } else { $raw_lower = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'; $raw_numbers = '1 2 3 4 5 6 7 8 9 0'; $raw_punc = '# $ % ^ & * ( ) _ - + = . , [ ] { } : |'; } $llower = explode(' ', $raw_lower); shuffle($llower); $lupper = explode(' ', strtoupper($raw_lower)); shuffle($lupper); $numbers = explode(' ', $raw_numbers); shuffle($numbers); $punc = explode(' ', $raw_punc); shuffle($punc); if ($lowercase > 0) { $outarray = array_merge($outarray, a_array_rand($llower, $lowercase)); } if ($uppercase > 0) { $outarray = array_merge($outarray, a_array_rand($lupper, $uppercase)); } if ($digits > 0) { $outarray = array_merge($outarray, a_array_rand($numbers, $digits)); } if ($punctuation > 0) { $outarray = array_merge($outarray, a_array_rand($punc, $punctuation)); } $num_spec = $lowercase + $uppercase + $digits + $punctuation; if ($num_spec < $length) { $leftover = array(); if ($lowercase > 0) { $leftover = array_merge($leftover, $llower); } if ($uppercase > 0) { $leftover = array_merge($leftover, $lupper); } if ($digits > 0) { $leftover = array_merge($leftover, $numbers); } if ($punctuation > 0) { $leftover = array_merge($leftover, $punc); } if (count($leftover) == 0) { $leftover = array_merge($leftover, $llower, $lupper, $numbers, $punc); } shuffle($leftover); $outarray = array_merge($outarray, a_array_rand($leftover, $length - $num_spec)); } shuffle($outarray); $return = implode('', $outarray); if (DEBUG_ENABLED) { debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $return); } return $return; }