[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 password_funcs.php

Zen Cart 源代码 password_funcs.php




下载文件

文件名: password_funcs.php
文件类型: PHP文件
文件大小: 5.99 KiB
MD5: 25551d771fa8c83b4c80b0cc888850f9

password_funcs.php - 关闭高亮
  1. <?php
  2. /**
  3.  * password_funcs functions
  4.  *
  5.  * @package functions
  6.  * @copyright Copyright 2003-2014 Zen Cart Development Team
  7.  * @copyright Portions Copyright 2003 osCommerce
  8.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9.  * @version GIT: $Id: Author: Ian Wilson  Wed Feb 19 15:57:35 2014 +0000 Modified in v1.5.3 $
  10.  */
  11. // //
  12. // This function validates a plain text password with an encrpyted password
  13. function zen_validate_password($plain, $encrypted, $userRef = NULL)
  14. {
  15.   $zcPassword = zcPassword::getInstance(PHP_VERSION);
  16.   return $zcPassword->validatePassword($plain, $encrypted);
  17. }
  18.  
  19. // //
  20. // This function makes a new password from a plaintext password.
  21. function zen_encrypt_password($plain)
  22. {
  23.   $password = '';
  24.  
  25.   for($i = 0; $i < 10; $i ++) {
  26.     $password .= zen_rand();
  27.   }
  28.  
  29.   $salt = substr(md5($password), 0, 2);
  30.  
  31.   $password = md5($salt . $plain) . ':' . $salt;
  32.  
  33.   return $password;
  34. }
  35. function zen_encrypt_password_new($plain)
  36. {
  37.   $password = '';
  38.   for($i = 0; $i < 40; $i ++) {
  39.     $password .= zen_rand();
  40.   }
  41.   $salt = hash('sha256', $password);
  42.   $password = hash('sha256', $salt . $plain) . ':' . $salt;
  43.   return $password;
  44. }
  45. // //
  46. function zen_create_random_value($length, $type = 'mixed')
  47. {
  48.   if (($type != 'mixed') && ($type != 'chars') && ($type != 'digits'))
  49.     return false;
  50.  
  51.   $rand_value = '';
  52.   while ( strlen($rand_value) < $length ) {
  53.     if ($type == 'digits') {
  54.       $char = zen_rand(0, 9);
  55.     } else {
  56.       $char = chr(zen_rand(0, 255));
  57.     }
  58.     if ($type == 'mixed') {
  59.       if (preg_match('/^[a-z0-9]$/i', $char))
  60.         $rand_value .= $char;
  61.     } elseif ($type == 'chars') {
  62.       if (preg_match('/^[a-z]$/i', $char))
  63.         $rand_value .= $char;
  64.     } elseif ($type == 'digits') {
  65.       if (preg_match('/^[0-9]$/', $char))
  66.         $rand_value .= $char;
  67.     }
  68.   }
  69.  
  70.   if ($type == 'mixed' && ! preg_match('/^(?=.*[\w]+.*)(?=.*[\d]+.*)[\d\w]{' . $length . ',}$/', $rand_value)) {
  71.     $rand_value .= zen_rand(0, 9);
  72.   }
  73.  
  74.   return $rand_value;
  75. }
  76. /**
  77.  * Returns entropy using a hash of various available methods for obtaining
  78.  * random data.
  79.  * The default hash method is "sha1" and the default size is 32.
  80.  *
  81.  * @param string $hash
  82.  *          the hash method to use while generating the hash.
  83.  * @param int $size
  84.  *          the size of random data to use while generating the hash.
  85.  * @return string the randomized salt
  86.  */
  87. function zen_get_entropy($hash = 'sha1', $size = 32)
  88. {
  89.   $data = null;
  90.   if (! in_array($hash, hash_algos()))
  91.     $hash = 'sha1';
  92.   if (! is_int($size))
  93.     $size = (int)$size;
  94.  
  95.     // Use openssl if available
  96.   if (function_exists('openssl_random_pseudo_bytes')) {
  97.     // echo('Attempting to create entropy using openssl');
  98.     $entropy = openssl_random_pseudo_bytes($size, $strong);
  99.     if ($strong)
  100.       $data = $entropy;
  101.     unset($strong, $entropy);
  102.   }
  103.  
  104.   // Use mcrypt with /dev/urandom if available
  105.   if ($data === null && function_exists('mcrypt_create_iv') && (
  106.     // There is a bug in Windows + IIS in older versions of PHP
  107.     (
  108. strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' || version_compare(PHP_VERSION, '5.3.7', '>='))))
  109.   {
  110.     // echo('Attempting to create entropy using mcrypt');
  111.     $entropy = mcrypt_create_iv($size, MCRYPT_DEV_URANDOM);
  112.     if ($entropy !== FALSE)
  113.       $data = $entropy;
  114.     unset($entropy);
  115.   }
  116.  
  117.   if ($data === null) {
  118.     // Fall back to using /dev/urandom if available
  119.     $fp = @fopen('/dev/urandom', 'rb');
  120.     if ($fp !== FALSE) {
  121.       // echo('Attempting to create entropy using /dev/urandom');
  122.       $entropy = @fread($fp, $size);
  123.       @fclose($fp);
  124.       if (strlen($entropy) == $size)
  125.         $data = $entropy;
  126.       unset($fp, $entropy);
  127.     }
  128.   }
  129.  
  130.   // Final fallback (mixture of various methods)
  131.   if ($data === null) {
  132.     // echo('Attempting to create entropy using FINAL FALLBACK');
  133.     if (!defined('DIR_FS_ROOT')) define('DIR_FS_ROOT', DIR_FS_CATALOG);
  134.     $filename = DIR_FS_ROOT . 'includes/configure.php';
  135.     $stat = @stat($filename);
  136.     if ($stat === FALSE) {
  137.       $stat = array(
  138.           'microtime' => microtime()
  139.       );
  140.     }
  141.     $stat ['mt_rand'] = mt_rand();
  142.     $stat ['file_hash'] = hash_file($hash, $filename, TRUE);
  143.  
  144.     // Attempt to get a random value on windows
  145.     // http://msdn.microsoft.com/en-us/library/aa388176(VS.85).aspx
  146.     if (@class_exists('COM')) {
  147.       try {
  148.         $CAPI_Util = new COM('CAPICOM.Utilities.1');
  149.         $entropy = $CAPI_Util->GetRandom($size, 0);
  150.  
  151.         if ($entropy) {
  152.           // echo('Adding random data to entropy using CAPICOM.Utilities');
  153.           $stat ['CAPICOM_Utilities_random'] = md5($entropy, TRUE);
  154.         }
  155.         unset($CAPI_Util, $entropy);
  156.       } catch ( Exception $ex ) {
  157.       }
  158.     }
  159.  
  160.     // echo('Adding random data to entropy using file information and contents');
  161.     @shuffle($stat);
  162.     foreach ( $stat as $value ) {
  163.       $data .= $value;
  164.     }
  165.     unset($filename, $value, $stat);
  166.   }
  167.  
  168.   return hash($hash, $data);
  169. }
  170. function zen_create_PADSS_password($length = 8)
  171. {
  172.   $charsAlpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  173.   $charsNum = '0123456789';
  174.   $charsMixed = $charsAlpha . $charsNum;
  175.   $password = "";
  176.   for($i = 0; $i < $length; $i ++) {
  177.     $addChar = substr($charsMixed, zen_pwd_rand(0, strlen($charsMixed) - 1), 1);
  178.     while ( strpos($password, $addChar) ) {
  179.       $addChar = substr($charsMixed, zen_pwd_rand(0, strlen($charsMixed) - 1), 1);
  180.     }
  181.     $password .= $addChar;
  182.   }
  183.   if (! preg_match('/[0-9]/', $password)) {
  184.     $addChar = substr($charsNum, zen_pwd_rand(0, strlen($charsNum) - 1), 1);
  185.     $addPos = zen_pwd_rand(0, strlen($password) - 1);
  186.     $password [$addPos] = $addChar;
  187.   }
  188.   return $password;
  189. }
  190. function zen_pwd_rand($min = 0, $max = 10)
  191. {
  192.   static $seed;
  193.   if (! isset($seed))
  194.     $seed = zen_get_entropy();
  195.   $random = hash('sha1', zen_get_entropy() . $seed);
  196.   $random .= hash('sha1', zen_get_entropy() . $random);
  197.   $random = hash('sha1', $random);
  198.   $random = substr($random, 0, 8);
  199.   $value = abs(hexdec($random));
  200.   $value = $min + (($max - $min + 1) * ($value / (4294967295 + 1)));
  201.   $value = abs(intval($value));
  202.   return $value;
  203. }
  204.