ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/functions/password_funcs.php
Go to the documentation of this file.
00001 <?php
00010 
00011 // This function validates a plain text password with an encrpyted password
00012   function zen_validate_password($plain, $encrypted) {
00013     if (zen_not_null($plain) && zen_not_null($encrypted)) {
00014 // split apart the hash / salt
00015       $stack = explode(':', $encrypted);
00016 
00017       if (sizeof($stack) != 2) return false;
00018 
00019       if (md5($stack[1] . $plain) == $stack[0]) {
00020         return true;
00021       }
00022     }
00023 
00024     return false;
00025   }
00026 
00028 // This function makes a new password from a plaintext password.
00029   function zen_encrypt_password($plain) {
00030     $password = '';
00031 
00032     for ($i=0; $i<10; $i++) {
00033       $password .= zen_rand();
00034     }
00035 
00036     $salt = substr(md5($password), 0, 2);
00037 
00038     $password = md5($salt . $plain) . ':' . $salt;
00039 
00040     return $password;
00041   }
00042 
00044 // This function comes up with a plaintext word.
00045 // You can then pass this word over to zen_encrypt_password or another similar function
00046   function zen_create_random_value($length, $type = 'mixed') {
00047     if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) return false;
00048 
00049     $rand_value = '';
00050     while (strlen($rand_value) < $length) {
00051       if ($type == 'digits') {
00052         $char = zen_rand(0,9);
00053       } else {
00054         $char = chr(zen_rand(0,255));
00055       }
00056       if ($type == 'mixed') {
00057         if (preg_match('/^[a-z0-9]$/i', $char)) $rand_value .= $char;
00058       } elseif ($type == 'chars') {
00059         if (preg_match('/^[a-z]$/i', $char)) $rand_value .= $char;
00060       } elseif ($type == 'digits') {
00061         if (preg_match('/^[0-9]$/', $char)) $rand_value .= $char;
00062       }
00063     }
00064 
00065     if ($type == 'mixed' && !preg_match('/^(?=.*[\w]+.*)(?=.*[\d]+.*)[\d\w]{' . $length . ',}$/', $rand_value)) {
00066       $rand_value .= zen_rand(0,9);
00067     }
00068 
00069     return $rand_value;
00070   }
 All Data Structures Namespaces Files Functions Variables Enumerations