<?php
/*
   $Id: password_funcs.php,v 1.1.1.1 2006/05/05 15:00:45 simon Exp $

   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 (($plain) && ($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;
}

function tep_encrypt_password_new($plain) {
	$password = '';

	$salt = md5($password);

	$password = md5($salt . $plain) . ':' . $salt;

	return $salt;
}

function tep_rand($min = null, $max = null) {
    static $seeded;

    if (!isset($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();
    }
  }

?>
