array( 'PublicToken' => "PublicToken", 'PrivateToken' => "PrivateToken", 'Salt' => "Salt" ), 'numeric' => array( 'UserId' => "UserId", 'KeyType' => "KeyType" ), 'user' => array( 'User' => "UserId" ) ); public function GenerateSalt() { $this->uSalt = random_string(10); } public function GenerateHash() { if(!empty($this->uSalt)) { if(!empty($this->uToken)) { $this->uPrivateToken = $this->CreateHash($this->uToken); } else { throw new MissingDataException("ApiKey object is missing a token."); } } else { throw new MissingDataException("ApiKey object is missing a salt."); } } public function CreateHash($input) { global $settings; $hash = crypt($input, "$5\$rounds=50000\${$this->uSalt}{$settings['salt']}$"); $parts = explode("$", $hash); return $parts[4]; } public function VerifyToken($token) { if($this->CreateHash($token) == $this->sPrivateToken) { return true; } else { return false; } } public function SetPrivateToken($token) { $this->uToken = $token; $this->GenerateHash(); } }