private function _handleRegister()
 {
     $errors = array();
     /* image validation */
     if (empty($_FILES["picture"]['name'])) {
         $errors["picture"] = "Geen file geselecteerd";
     }
     if (empty($errors)) {
         if (!empty($_FILES["picture"]['errors'])) {
             $errors["picture"] = "Er is iets fout gegaan";
         }
     }
     if (empty($errors)) {
         $size = getimagesize($_FILES["picture"]['tmp_name']);
         if (empty($size)) {
             $errors["picture"] = "Uploadbestand is geen afbeelding";
         }
     }
     /* form validation */
     if (empty($_POST['username'])) {
         $errors['username'] = '******';
     } else {
         $existing = $this->userDAO->selectByUsername($_POST['username']);
         if (!empty($existing)) {
             $errors['username'] = '******';
         }
     }
     if (empty($_POST['password'])) {
         $errors['password'] = '******';
     }
     if (empty($errors)) {
         $this->_handleImageUpload($_FILES);
         /* add user to database */
         $hasher = new \Phpass\Hash();
         $inserteduser = $this->userDAO->insert(array('username' => $_POST['username'], 'picture' => $_FILES['picture']['name'], 'password' => $hasher->hashPassword($_POST['password']), 'role' => 1, 'group_id' => 0));
         if (!empty($inserteduser)) {
             $_SESSION['info'] = 'Registratie Succesvol!';
             $_SESSION['user'] = $inserteduser;
             $this->redirect('index.php');
         }
     }
     $_SESSION['error'] = 'Registratie mislukt.';
     $this->set('errors', $errors);
 }
Example #2
0
 /**
  * Hash Password
  *
  * A useful function that can be called without creating a new instance of the User model, to transform a
  * string into a password hash.
  *
  * @static
  * @access public
  * @param string
  * @return string
  */
 public static function hashPassword($password)
 {
     $phpass = new \Phpass\Hash();
     return $phpass->hashPassword($password);
 }
 /**
  * Migrate Up
  *
  * @access public
  * @return void
  */
 public function up()
 {
     // Create a user.
     $phpass = new \Phpass\Hash();
     $this->insert('{{user}}', array('username' => 'admin', 'password' => $phpass->hashPassword('admin'), 'firstname' => 'System', 'nickname' => 'Sysadmin', 'lastname' => 'Administrator', 'created' => microtime(true)));
 }
Example #4
0
 public function setPassword($password)
 {
     $phpassHash = new \Phpass\Hash();
     $this->password = $phpassHash->hashPassword($password);
     return $this;
 }
Example #5
0
    $post = $app->request->post();
    if (empty($post)) {
        $post = (array) json_decode($app->request()->getBody());
    }
    if (!empty($post['name']) && !empty($post['email']) && !empty($post['password'])) {
        $errors = array();
        $words = explode(' ', $post['name']);
        if (count($words) < 2) {
            array_push($errors, "Voor -en achternaam.");
        }
        $pattern = "/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}\$/";
        if (preg_match($pattern, $post['email']) == 0) {
            array_push($errors, "Foute email...");
        }
        if (count($errors) == 1) {
            echo '{"error": "' . $errors[0] . '"}';
        }
        if (count($errors) == 2) {
            echo '{"error": "Foute naam en email."}';
        } else {
            if (count($errors) == 0) {
                $hasher = new \Phpass\Hash();
                $passwordHash = $hasher->hashPassword($post["password"]);
                $post["password"] = $passwordHash;
                echo json_encode($userDAO->insert($post), JSON_NUMERIC_CHECK);
            }
        }
    } else {
        echo '{"error": "Vul alles in..."}';
    }
});