/** * generate the current restore key * * @param User $user * @return string */ public function restore_key($user) { return \CCStr::hash($user->password . '@' . $user->{$this->config->user_key} . '%' . \CCIn::client()->agent); }
/** * test extentsion */ public function testHash() { ClanCats::$config->set('security.hash', 'sha1'); $this->assertEquals(strlen(CCStr::hash('testing around')), 40); ClanCats::$config->set('security.hash', 'md5'); $this->assertEquals(strlen(CCStr::hash('testing around')), 32); }
/** * get the client data * * @param string $key * @return mixed */ public function client($key = null) { // check if we already set the client object if (is_null($this->client)) { // make client $this->client = new \stdClass(); /* * get clients ip address */ // Cloudlfare fix if ($this->has_server('HTTP_CF_CONNECTING_IP')) { $this->client->ip = $this->server('HTTP_CF_CONNECTING_IP'); } elseif ($this->has_server('HTTP_X_FORWARDED_FOR')) { $this->client->ip = $this->server('HTTP_X_FORWARDED_FOR'); } elseif ($this->has_server('HTTP_CLIENT_IP')) { $this->client->ip = $this->server('HTTP_CLIENT_IP'); } else { $this->client->ip = $this->server('REMOTE_ADDR', '127.0.0.1'); } /* * set clients user agent */ $this->client->agent = $this->server('HTTP_USER_AGENT', ''); /* * set clients port */ $this->client->port = $this->server('REMOTE_PORT', ''); /* * set clients fingerprint based on host and agent */ $this->client->fingerprint = CCStr::hash($this->client('agent') . $this->client('ip')); /* * set clients language */ $this->client->language = CCLang::set_current($this->server('HTTP_ACCEPT_LANGUAGE')); } // return the object if (is_null($key)) { return $this->client; } // return a special key return $this->client->{$key}; }
/** * Always hash the passwort * * @param string $password * @return string */ protected function _set_modifier_password($password) { return \CCStr::hash($password); }