Created
January 28, 2010 05:25
-
-
Save chucktrukk/288461 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//File: osc/includes/password_funcs.php | |
/* | |
$Id: password_funcs.php 1739 2007-12-20 00:52:16Z hpdl $ | |
osCommerce, Open Source E-Commerce Solutions | |
http://www.oscommerce.com | |
Copyright (c) 2003 osCommerce | |
Released under the GNU General Public License | |
*/ | |
//// | |
// This funstion validates a plain text password with an | |
// encrpyted password | |
function tep_validate_password($plain, $encrypted) { | |
if (tep_not_null($plain) && tep_not_null($encrypted)) { | |
// split apart the hash / salt | |
$stack = explode(':', $encrypted); | |
if (sizeof($stack) != 2) return false; | |
if (md5($stack[1] . $plain) == $stack[0]) { | |
return true; | |
} | |
} | |
return false; | |
} | |
//// | |
// This function makes a new password from a plaintext password. | |
function tep_encrypt_password($plain) { | |
$password = ''; | |
for ($i=0; $i<10; $i++) { | |
$password .= tep_rand(); | |
} | |
$salt = substr(md5($password), 0, 2); | |
$password = md5($salt . $plain) . ':' . $salt; | |
return $password; | |
} | |
//tep_rand function | |
// Return a random value | |
function tep_rand($min = null, $max = null) { | |
static $seeded; | |
if (!$seeded) { | |
mt_srand((double)microtime()*1000000); | |
$seeded = true; | |
} | |
if (isset($min) && isset($max)) { | |
if ($min >= $max) { | |
return $min; | |
} else { | |
return mt_rand($min, $max); | |
} | |
} else { | |
return mt_rand(); | |
} | |
} | |
function tep_not_null($value) { | |
if (is_array($value)) { | |
if (sizeof($value) > 0) { | |
return true; | |
} else { | |
return false; | |
} | |
} else { | |
if ( (is_string($value) || is_int($value)) && ($value != '') && ($value != 'NULL') && (strlen(trim($value)) > 0)) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment