<commit_before><?
/**
 * $Id$
 *
 * Code to implement activation procedures
 *
 * Utility script: cron\cleanup_activations.php
 * 		This script deletes all > 30 day old entries from tblActivation
 *
 * \todo cleanup script that deletes un-activated users entirely
 * \todo finish api/human_test.php implementation
 *
 * \author <NAME>, 2007-2008 <<EMAIL>>
 */

	define('ACTIVATE_CAPTCHA',		1);
	define('ACTIVATE_EMAIL',		2);
	define('ACTIVATE_SMS',			3);
	define('ACTIVATE_CHANGE_PWD',	4);		//used to allow the user to set a new password from a email link when he forgot password
	define('ACTIVATE_ACCOUNT',		5);		//used to activate a pre-generated account

	$config['activate']['expire_time_captcha']		= 60*5;			///< 5 minutes
	$config['activate']['expire_time_email']		= (12*60*60); 	///< 12 hours
	$config['activate']['expire_time_sms']			= (12*60*60);	///< 12 hours
	$config['activate']['expire_time_change_pwd']	= (6*60*60); 	///< 6 hours

	/**
	 * Returns an unused numeric activation code
	 *
	 * \param $lo lower limit of code
	 * \param $hi upper limit of code
	 * \return unused numeric activation code
	 */
	function generateActivationCode($lo, $hi)
	{
		global $db;

		do {
			$code = mt_rand($lo, $hi);
			$q = 'SELECT COUNT(*) FROM tblActivation WHERE rnd="'.$code.'"';
		} while ($db->getOneItem($q));

		return $code;
	}

	function getActivationExpireTime($_type)
	{
		global $config;
		switch ($_type)
		{
			case ACTIVATE_CAPTCHA:		return $config['activate']['expire_time_captcha'];
			case ACTIVATE_EMAIL:		return $config['activate']['expire_time_email'];
			case ACTIVATE_SMS:			return $config['activate']['expire_time_sms'];
			case ACTIVATE_CHANGE_PWD:	return $config['activate']['expire_time_change_pwd'];
		}
	}

	/**
	 * Verify if activation code is valid
	 *
	 * \param $_type type
	 * \param $_code activation code
	 * \param $_answer is string for CAPTCHA's, userId for email/sms activation<commit_msg>added default time for ACTIVATE_ACCOUNT<commit_after><?
/**
 * $Id$
 *
 * Code to implement activation procedures
 *
 * Utility script: cron\cleanup_activations.php
 * 		This script deletes all > 30 day old entries from tblActivation
 *
 * \todo cleanup script that deletes un-activated users entirely
 * \todo finish api/human_test.php implementation
 *
 * \author <NAME>, 2007-2008 <<EMAIL>>
 */

	define('ACTIVATE_CAPTCHA',		1);
	define('ACTIVATE_EMAIL',		2);
	define('ACTIVATE_SMS',			3);
	define('ACTIVATE_CHANGE_PWD',	4);		//used to allow the user to set a new password from a email link when he forgot password
	define('ACTIVATE_ACCOUNT',		5);		//used to activate a pre-generated account

	$config['activate']['expire_time_captcha']		= 60*5;			///< 5 minutes
	$config['activate']['expire_time_email']		= (12*60*60); 	///< 12 hours
	$config['activate']['expire_time_sms']			= (12*60*60);	///< 12 hours
	$config['activate']['expire_time_change_pwd']	= (6*60*60); 	///< 6 hours
	$config['activate']['expire_time_account']		= (24*60*60);	///< 24 hours

	/**
	 * Returns an unused numeric activation code
	 *
	 * \param $lo lower limit of code
	 * \param $hi upper limit of code
	 * \return unused numeric activation code
	 */
	function generateActivationCode($lo, $hi)
	{
		global $db;

		do {
			$code = mt_rand($lo, $hi);
			$q = 'SELECT COUNT(*) FROM tblActivation WHERE rnd="'.$code.'"';
		} while ($db->getOneItem($q));

		return $code;
	}

	function getActivationExpireTime($_type)
	{
		global $config;
		switch ($_type)
		{
			case ACTIVATE_CAPTCHA:		return $config['activate']['expire_time_captcha'];
			case ACTIVATE_EMAIL:		return $config['activate']['expire_time_email'];
			case ACTIVATE_SMS:			return $config['activate']['expire_time_sms'];
			case ACTIVATE_CHANGE_PWD:	return $config['activate']['expire_time_change_pwd'];
			case ACTIVATE_ACCOUNT:		return $config['activate']['expire_time_account'];
			default: die('UNKNOWN TYPE '.$_type);
		}
	}

	/**
	 * Verify if activation code is valid
	 *
	 * \param $_type type
	 * \param $_code activation code
	 * \param $_answer is string for CAPTCHA's, userId for email/sms activation
{'fraction_non_alphanumeric': 0.14811181951937225, 'fraction_numerical': 0.022069641981363415, 'mean_word_length': 4.256443298969073, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5810589', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1378, 'n_words': 363}