src/User.php
private function genToken($tokenLen = null)
	{
		$this->debug->groupCollapsed(__METHOD__);
		$tokenLen = isset($tokenLen)
			? $tokenLen
			: $this->cfg['tokenLen'];
		$token = '';
		if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) {
			$token = mcrypt_create_iv($tokenLen, MCRYPT_DEV_URANDOM);
		}
		if (empty($token) && function_exists('openssl_random_pseudo_bytes')) {
			$token = openssl_random_pseudo_bytes($tokenLen);
		}
		if (empty($token) && is_readable('/dev/urandom')) {
			$file = fopen('/dev/urandom', 'r');
			$len = strlen($token);
			while ($len < $tokenLen) {
				$token .= fread($file, $tokenLen - $len);
				$len = strlen($token);
			}
			fclose($file);
		}
		$this->debug->log('token', $token);
		$this->debug->groupEnd();
		return $token;
	}
private function genToken($tokenLen = null)
	{
		$this->debug->groupCollapsed(__METHOD__);
		$tokenLen = isset($tokenLen)
			? $tokenLen
			: $this->cfg['tokenLen'];
		$token = '';
		if (function_exists('mcrypt_create_iv') && !defined('PHALANGER')) {
			$token = mcrypt_create_iv($tokenLen, MCRYPT_DEV_URANDOM);
		}
		if (empty($token) && function_exists('openssl_random_pseudo_bytes')) {
			$token = openssl_random_pseudo_bytes($tokenLen);
		}
		if (empty($token) && is_readable('/dev/urandom')) {
			$file = fopen('/dev/urandom', 'r');
			$len = strlen($token);
			while ($len < $tokenLen) {
				$token .= fread($file, $tokenLen - $len);
				$len = strlen($token);
			}
			fclose($file);
		}
		$this->debug->log('token', $token);
		$this->debug->groupEnd();
		return $token;
	}
private function genToken ( $ tokenLen = null ) { $ this -> debug -> groupCollapsed ( __METHOD__ ) ; $ tokenLen = isset ( $ tokenLen ) ? $ tokenLen : $ this -> cfg [ 'tokenLen' ] ; $ token = '' ; if ( function_exists ( 'mcrypt_create_iv' ) && ! defined ( 'PHALANGER' ) ) { $ token = mcrypt_create_iv ( $ tokenLen , MCRYPT_DEV_URANDOM ) ; } if ( empty ( $ token ) && function_exists ( 'openssl_random_pseudo_bytes' ) ) { $ token = openssl_random_pseudo_bytes ( $ tokenLen ) ; } if ( empty ( $ token ) && is_readable ( '/dev/urandom' ) ) { $ file = fopen ( '/dev/urandom' , 'r' ) ; $ len = strlen ( $ token ) ; while ( $ len < $ tokenLen ) { $ token .= fread ( $ file , $ tokenLen - $ len ) ; $ len = strlen ( $ token ) ; } fclose ( $ file ) ; } $ this -> debug -> log ( 'token' , $ token ) ; $ this -> debug -> groupEnd ( ) ; return $ token ; }
generate crypto strength token

@param integer $tokenLen optional token length (bytes)

@return string raw binary string
generate crypto strength token