public function add(array $errors = array())
 {
     if (!$this->session->get('user')->isRegistered()) {
         header('Location: index.php');
         exit;
     }
     $view = new PHPView('GuestBook/add');
     $data = $this->request->post('gb_item', array());
     $data += array('id' => 0, 'name' => '', 'location' => '', 'greeting' => '');
     $view->assignAll($data);
     $view->assign('errors', $errors);
     $token = base64_encode(Security::makeRandomString());
     $this->session->set('csrf.token', $token);
     $view->assign('csrf', $token);
     return $view;
 }
 public function register($message = '')
 {
     if ($this->session->get('user')->isRegistered()) {
         header('Location: index.php');
         exit;
     }
     $view = new SmartyView('User/register');
     $token = base64_encode(Security::makeRandomString());
     $this->session->set('csrf.token', $token);
     $view->assign('csrf', $token);
     $view->assign('message', $message);
     return $view;
 }
 public function setPassword($new)
 {
     $this->salt = Security::makeRandomString(10);
     $this->password = Security::PBKDF2($new, $this->salt, $this->algo, $this->cycles, $this->iterations);
 }