Exemple #1
0
 /**
  * Logs in the user
  * Sets the view to the the return url if given, the homepage, or the login
  * view if authentication fails
  */
 public function loginHandler()
 {
     $values = array();
     $data = $this->data;
     if ($this->isPost() && isset($data['username']) && isset($data['password'])) {
         $user = \App\Models\User::withUsernameAndPassword($data['username'], hash_data($data['password']));
         if (!is_null($user)) {
             if (isset($data['return_url']) && $data['return_url'] != '') {
                 $this->redirect($data['return_url']);
             } else {
                 $this->redirect();
             }
         } else {
             $values['login_message'] = 'Wrong user name and password combination';
             $this->view('user/login.php', $values);
         }
     } else {
         $this->view('user/login.php');
     }
 }
Exemple #2
0
 /**
  * Creates and returns a key to be used to mark this users session in the database and in the $_SESSION array
  * @param User $user
  * @return string
  */
 protected static function getSessionKey($user)
 {
     return hash_data($user->username . $user->regDate . time());
 }
Exemple #3
0
 public function testHash_DataWrongHash()
 {
     $data = hash_data('1');
     $this->assertFalse('8513c69d070a008df008aef8624ed24afc81b170d242faf5fafe853d4fe9bf8aa7badfb0fd045d7b350b19fbf8ef6b2a51f17a07a1f6819abc9ba5ce43324245' == $data);
 }