public function render($body, $template) { session_start(); if (!isset($_SESSION['admin'])) { header('HTTP/1.0 401 Unautorized'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->user = trim(strip_tags($_POST['user'])); $this->pwd = trim(strip_tags($_POST['pwd'])); if ($this->user and $this->pwd) { $secure = new Secure(); if ($result = $secure->userExists($this->user)) { list($login, $password, $salt, $iteration) = explode(':', $result); if ($secure->getHash($this->pwd, $salt, $iteration) == $password) { $_SESSION['admin'] = true; header('Location: /admin'); } else { $this->result = 'Неравильный логин или пароль'; } } else { $this->result = 'Неравильный логин или пароль'; } } else { $this->result = 'Заполнены не все поля'; } } include $template; } else { header('Location: /admin'); } }
public function addUser() { $secure = new Secure(); if (!$this->salt) { $this->salt = str_replace('=', '', base64_encode(md5(microtime() . md5(microtime())))); } if (!$secure->userExists($this->user)) { $hash = $secure->getHash($this->pwd, $this->salt, $this->iteration); if ($secure->saveHash($this->user, $hash, $this->salt, $this->iteration)) { $this->result = "Хеш {$pwd} успешно записан в файл"; } else { $this->result = "Произошла ошибка при записи хеша"; } } else { $this->result = "Пользователь с таким именем уже существует"; } }