Resources/contao/models/C4gActivationkeyModel.php
public static function generateActivationkey( $action, $saveInDB=true, $durabilityInDays=30 )
	{
		// generate a unique key
		$attempts = 42;
		do {
			$key = md5(uniqid(rand(), true));
			$hasKey = C4gActivationkeyModel::findOneBy( 'activationkey', $key );
			$attempts--;
		} while (!empty( $hasKey ) && $attempts > 0);
		if (!empty( $hasKey )) { return false; }

		// save key in database
		if ($saveInDB) {
			$objKey = new C4gActivationkeyModel();
			$objKey->activationkey = hash('sha256', $key);
			$objKey->expiration_date = strtotime('+' . $durabilityInDays . ' days', time());
			$objKey->key_action = $action;
			$objKey->save();
		}

		return $key;
	}
public static function generateActivationkey( $action, $saveInDB=true, $durabilityInDays=30 )
	{
		// generate a unique key
		$attempts = 42;
		do {
			$key = md5(uniqid(rand(), true));
			$hasKey = C4gActivationkeyModel::findOneBy( 'activationkey', $key );
			$attempts--;
		} while (!empty( $hasKey ) && $attempts > 0);
		if (!empty( $hasKey )) { return false; }

		// save key in database
		if ($saveInDB) {
			$objKey = new C4gActivationkeyModel();
			$objKey->activationkey = hash('sha256', $key);
			$objKey->expiration_date = strtotime('+' . $durabilityInDays . ' days', time());
			$objKey->key_action = $action;
			$objKey->save();
		}

		return $key;
	}
Generates an Activationkey and saves it in the DB, if $saveInDB is true
@param  string  $action
@param  boolean $saveInDB
@return string