Exemple #1
0
 protected function processData()
 {
     //Alpha-num
     sanitizeUsername($this->username);
     //Verify username and password length requirements
     if (strlen($this->username) > 40) {
         throw new Exception("Username must be shorter than 40 characters");
     }
     if (strlen($this->username) > 72) {
         throw new Exception("Password must be shorter than 72 characters");
     }
     //verify username available
     $conn = getDatabaseConnection();
     $availabilityQuery = new UsernameAvailabilityQuery($conn, $this->username);
     $available = $availabilityQuery->getNumRows() == 0;
     if ($available) {
         //hash pw
         $this->password = password_hash($this->password, PASSWORD_DEFAULT);
         //add user
         $addUserQuery = new AddUserQuery($conn, $this->username, $this->password);
         $addUserQuery->query();
     } else {
         //username taken
         throw new Exception("Username taken");
     }
     return true;
 }
Exemple #2
0
 protected function processData()
 {
     //Alpha-num
     sanitizeUsername($this->username);
     //Verify username and password length requirements
     if (strlen($this->username) > 40) {
         throw new Exception("Username invalid");
     }
     if (strlen($this->username) > 72) {
         throw new Exception("Password incorrect");
     }
     //verify password
     $conn = getDatabaseConnection();
     $storedPassQuery = new PasswordQuery($conn, $this->username);
     $storedPassHash = $storedPassQuery->getPassword();
     $valid = password_verify($this->password, $storedPassHash);
     return $valid;
 }