public function create_token($password, $valueToStore=null, $tokenId=null, $lifetime=null, $maxUses=null, $tokenType=0, $uid=0) {
		
		if(is_null($tokenId) || strlen($tokenId) < 1) {
			$tokenId = $this->generate_token_string();
		}
		
		
		$finalHash = password_hash($password, $this->passAlgorithm);
		
		if(!is_numeric($tokenType)) {
			$tokenType = $this->lookup_token_type($tokenType);
		}
		
		$insertData = array(
			'auth_token_id'	=> $tokenId,
			'passwd'		=> $finalHash,
			'stored_value'	=> serialize($valueToStore),
			'token_type_id'	=> $tokenType,
			'uid'			=> $uid,
		);
		
		if(!is_null($maxUses) && is_numeric($maxUses)) {
			$insertData['max_uses'] = $maxUses;
		}
		try {
			$fields = "";
			$values = "";
			foreach($insertData as $k=>$v) {
				$fields = ToolBox::create_list($fields, $k);
				$values = ToolBox::create_list($values, ':'. $k);
			}
			
			if(!is_null($lifetime) && strlen($lifetime) > 0) {
				$fields .= ", expiration";
				$values .= ", NOW() + :life::interval";
				$insertData['life'] = $lifetime;
			}
			
			$sql = "INSERT INTO cswal_auth_token_table (". $fields .") VALUES (". $values .")";
			
			$numRows = $this->db->run_query($sql, $insertData);
			
			if($numRows != 1) {
				throw new LogicException(__METHOD__ .": unable to create token (". $numRows .")");
			}
		}
		catch(exception $e) {
			if(preg_match('/duplicate key value violates unique constraint/', $e->getMessage())) {
				throw new ErrorException(__METHOD__ .": attempt to create non-unique token (". $tokenId .")");
			}
			else {
				throw new ErrorException(__METHOD__ .": failed to create token::: ". $e->getMessage());
			}
		}
		
		return($tokenId);
	}
public function create_token($password, $valueToStore=null, $tokenId=null, $lifetime=null, $maxUses=null, $tokenType=0, $uid=0) {
		
		if(is_null($tokenId) || strlen($tokenId) < 1) {
			$tokenId = $this->generate_token_string();
		}
		
		
		$finalHash = password_hash($password, $this->passAlgorithm);
		
		if(!is_numeric($tokenType)) {
			$tokenType = $this->lookup_token_type($tokenType);
		}
		
		$insertData = array(
			'auth_token_id'	=> $tokenId,
			'passwd'		=> $finalHash,
			'stored_value'	=> serialize($valueToStore),
			'token_type_id'	=> $tokenType,
			'uid'			=> $uid,
		);
		
		if(!is_null($maxUses) && is_numeric($maxUses)) {
			$insertData['max_uses'] = $maxUses;
		}
		try {
			$fields = "";
			$values = "";
			foreach($insertData as $k=>$v) {
				$fields = ToolBox::create_list($fields, $k);
				$values = ToolBox::create_list($values, ':'. $k);
			}
			
			if(!is_null($lifetime) && strlen($lifetime) > 0) {
				$fields .= ", expiration";
				$values .= ", NOW() + :life::interval";
				$insertData['life'] = $lifetime;
			}
			
			$sql = "INSERT INTO cswal_auth_token_table (". $fields .") VALUES (". $values .")";
			
			$numRows = $this->db->run_query($sql, $insertData);
			
			if($numRows != 1) {
				throw new LogicException(__METHOD__ .": unable to create token (". $numRows .")");
			}
		}
		catch(exception $e) {
			if(preg_match('/duplicate key value violates unique constraint/', $e->getMessage())) {
				throw new ErrorException(__METHOD__ .": attempt to create non-unique token (". $tokenId .")");
			}
			else {
				throw new ErrorException(__METHOD__ .": failed to create token::: ". $e->getMessage());
			}
		}
		
		return($tokenId);
	}
public function create_token ( $ password , $ valueToStore = null , $ tokenId = null , $ lifetime = null , $ maxUses = null , $ tokenType = 0 , $ uid = 0 ) { if ( is_null ( $ tokenId ) || strlen ( $ tokenId ) < 1 ) { $ tokenId = $ this -> generate_token_string ( ) ; } $ finalHash = password_hash ( $ password , $ this -> passAlgorithm ) ; if ( ! is_numeric ( $ tokenType ) ) { $ tokenType = $ this -> lookup_token_type ( $ tokenType ) ; } $ insertData = array ( 'auth_token_id' => $ tokenId , 'passwd' => $ finalHash , 'stored_value' => serialize ( $ valueToStore ) , 'token_type_id' => $ tokenType , 'uid' => $ uid , ) ; if ( ! is_null ( $ maxUses ) && is_numeric ( $ maxUses ) ) { $ insertData [ 'max_uses' ] = $ maxUses ; } try { $ fields = "" ; $ values = "" ; foreach ( $ insertData as $ k => $ v ) { $ fields = ToolBox :: create_list ( $ fields , $ k ) ; $ values = ToolBox :: create_list ( $ values , ':' . $ k ) ; } if ( ! is_null ( $ lifetime ) && strlen ( $ lifetime ) > 0 ) { $ fields .= ", expiration" ; $ values .= ", NOW() + :life::interval" ; $ insertData [ 'life' ] = $ lifetime ; } $ sql = "INSERT INTO cswal_auth_token_table (" . $ fields . ") VALUES (" . $ values . ")" ; $ numRows = $ this -> db -> run_query ( $ sql , $ insertData ) ; if ( $ numRows != 1 ) { throw new LogicException ( __METHOD__ . ": unable to create token (" . $ numRows . ")" ) ; } } catch ( exception $ e ) { if ( preg_match ( '/duplicate key value violates unique constraint/' , $ e -> getMessage ( ) ) ) { throw new ErrorException ( __METHOD__ . ": attempt to create non-unique token (" . $ tokenId . ")" ) ; } else { throw new ErrorException ( __METHOD__ . ": failed to create token::: " . $ e -> getMessage ( ) ) ; } } return ( $ tokenId ) ; }
Build a token record in the database that can be authenticated against later.

@param $password		(str) matches checksum column...
@param $valueToStore (mixed, optional) item to be stored, will be serialized
@param $tokenId		(str, optional) key to match against
@param $lifetime		(str,optional) string (interval) representing how
long the token should last
@param $maxUses		(int,optional) Number of times it can be authenticated
against before being removed
@param $tokenType	(int/string,optional) type of token; can be a string
for looking up the given type
@param $uid			(int, optional) value for uid column

@return (string)		PASS: contains the token string.

@throws ErrorException
@throws LogicException
Build a token record in the database that can be authenticated against later .