[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文件
文件大小: 4.02 KiB
MD5: 08a7cbf82abb08b2ad7faa1f4be63a70

password_funcs.php - 关闭高亮
  1. <?php
  2. /**
  3.  * password_funcs functions
  4.  *
  5.  * @package functions
  6.  * @copyright Copyright 2003-2012 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 Aug 29 13:38:15 2012 +0100 Modified in v1.5.1 $
  10.  */
  11.  
  12. ////
  13. // This function validates a plain text password with an encrpyted password
  14. function zen_validate_password($plain, $encrypted)
  15. {
  16.   if (zen_not_null($plain) && zen_not_null($encrypted))
  17.   {
  18.     // split apart the hash / salt
  19.     $stack = explode(':', $encrypted);
  20.  
  21.     if (sizeof($stack) != 2)
  22.       return false;
  23.  
  24.     if (md5($stack[1] . $plain) == $stack[0])
  25.     {
  26.       return true;
  27.     }
  28.   }
  29.  
  30.   return false;
  31. }
  32. ////
  33. // This function makes a new password from a plaintext password.
  34. function zen_encrypt_password($plain)
  35. {
  36.   $password = '';
  37.  
  38.   for ($i = 0; $i < 10; $i++)
  39.   {
  40.     $password .= zen_rand();
  41.   }
  42.  
  43.   $salt = substr(md5($password), 0, 2);
  44.  
  45.   $password = md5($salt . $plain) . ':' . $salt;
  46.  
  47.   return $password;
  48. }
  49. ////
  50. function zen_create_random_value($length, $type = 'mixed')
  51. {
  52.   if (($type != 'mixed') && ($type != 'chars') && ($type != 'digits'))
  53.     return false;
  54.  
  55.   $rand_value = '';
  56.   while (strlen($rand_value) < $length)
  57.   {
  58.     if ($type == 'digits')
  59.     {
  60.       $char = zen_rand(0, 9);
  61.     } else
  62.     {
  63.       $char = chr(zen_rand(0, 255));
  64.     }
  65.     if ($type == 'mixed')
  66.     {
  67.       if (preg_match('/^[a-z0-9]$/i', $char))
  68.         $rand_value .= $char;
  69.     } elseif ($type == 'chars')
  70.     {
  71.       if (preg_match('/^[a-z]$/i', $char))
  72.         $rand_value .= $char;
  73.     } elseif ($type == 'digits')
  74.     {
  75.       if (preg_match('/^[0-9]$/', $char))
  76.         $rand_value .= $char;
  77.     }
  78.   }
  79.  
  80.   if ($type == 'mixed' && !preg_match('/^(?=.*[\w]+.*)(?=.*[\d]+.*)[\d\w]{' . $length . ',}$/', $rand_value))
  81.   {
  82.     $rand_value .= zen_rand(0, 9);
  83.   }
  84.  
  85.   return $rand_value;
  86. }
  87. function zen_get_entropy($seed)
  88. {
  89.   $entropy = '';
  90.   $fp = @fopen('/dev/urandom', 'rb');
  91.   if ($fp !== FALSE)
  92.   {
  93.     $entropy .= @fread($fp, 16);
  94.     //    echo "USING /dev/random" . "<br>";
  95.     @fclose($fp);
  96.   }
  97.   // MS-Windows platform?
  98.   if (@class_exists('COM'))
  99.   {
  100.     // http://msdn.microsoft.com/en-us/library/aa388176(VS.85).aspx
  101.     try
  102.     {
  103.       $CAPI_Util = new COM('CAPICOM.Utilities.1');
  104.       $entropy .= $CAPI_Util->GetRandom(16, 0);
  105.  
  106.       if ($entropy)
  107.       {
  108.         $entropy = md5($entropy, TRUE);
  109.         //echo "USING WINDOWS" . "<br>";
  110.       }
  111.     } catch (Exception $ex)
  112.     {
  113.       // echo 'Exception: ' . $ex->getMessage();
  114.     }
  115.   }
  116.   if (strlen($entropy) < 16)
  117.   {
  118.     $entropy = sha1_file('/includes/configure.php');
  119.     $entropy .= microtime() . mt_rand() . $seed;
  120.     //echo "USING FALLBACK" . "<br>";
  121.   }
  122.   return sha1($entropy);
  123. }
  124. function zen_create_PADSS_password($length = 8)
  125. {
  126.   $charsAlpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  127.   $charsNum = '0123456789';
  128.   $charsMixed = $charsAlpha . $charsNum;
  129.   $password = "";
  130.   for ($i = 0; $i < $length; $i++)
  131.   {
  132.     $addChar = substr($charsMixed, zen_pwd_rand(0, strlen($charsMixed) - 1), 1);
  133.     while (strpos($password, $addChar))
  134.     {
  135.       $addChar = substr($charsMixed, zen_pwd_rand(0, strlen($charsMixed) - 1), 1);
  136.     }
  137.     $password .= $addChar;
  138.   }
  139.   if (!preg_match('/[0-9]/', $password))
  140.   {
  141.     $addChar = substr($charsNum, zen_pwd_rand(0, strlen($charsNum) - 1), 1);
  142.     $addPos = zen_pwd_rand(0, strlen($password) - 1);
  143.     $password[$addPos] = $addChar;
  144.   }
  145.   return $password;
  146. }
  147. function zen_pwd_rand($min = 0, $max = 10)
  148. {
  149.   static $seed;
  150.   if (!isset($seed))
  151.     $seed = zen_get_entropy(microtime());
  152.   $random = zen_get_entropy($seed);
  153.   $random .= zen_get_entropy($random);
  154.   $random = sha1($random);
  155.   $random = substr($random, 0, 8);
  156.   $value = abs(hexdec($random));
  157.   $value = $min + (($max - $min + 1) * ($value / (4294967295 + 1)));
  158.   $value = abs(intval($value));
  159.   return $value;
  160. }
  161.