Example #1
0
 /**
  * Verifies registration data from user.
  *
  * @param  String $username       Input username.
  * @param  String $password       Input password.
  * @param  String $passwordRepeat Input repeated password.
  * @param  String $name 		  Input name. Can be empty.
  * @param  String $contact 		  Input contact. Can be empty.
  *
  * @throws RUsernameAndPasswordLengthException When $username length is less than 3
  *         									   AND $password length is less than 6.
  * @throws RPasswordLengthException 	When $password length is less than 6.
  * @throws RUsernameLengthException 	When $username length is less than 3.
  * @throws RPasswordMismatchException	When $password and $passwordRepeat are
  *         								NOT equal.
  * @throws RUserExistsException 		When $username already exist in the database.
  * @throws RInvalidCharactersException 	When $username contains invalid characters.
  *
  * @return boolean                 True if registration is successful.
  */
 public function verifyRegisterCredentials($username, $password, $passwordRepeat, $name, $contact)
 {
     if (strlen($username) < 3 && strlen($password) < 6) {
         throw new RUsernameAndPasswordLengthException();
     } else {
         if (strlen($password) < 6) {
             throw new RPasswordLengthException();
         } else {
             if (strlen($username) < 3) {
                 throw new RUsernameLengthException();
             } else {
                 if ($password !== $passwordRepeat) {
                     throw new RPasswordMismatchException();
                 } else {
                     if ($this->dal->findUserByUsername($username)) {
                         throw new RUserExistsException();
                     } else {
                         if (preg_match("/^[0-9A-Za-z_]+\$/", $username) == 0) {
                             throw new RInvalidCharactersException();
                         } else {
                             $user = new User($username, $password);
                             $infoJSON = '{"name": "' . $name . '", "contact": "' . $contact . '"}';
                             $user->setProfile($infoJSON);
                             $this->dal->add($user);
                             return true;
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * Used to update the logged in user's information (name, contact).
  *
  * @param  String $name
  * @param  String $contact
  */
 public function updateUserProfile($name, $contact)
 {
     $newInfo = json_encode(array('name' => $name, 'contact' => $contact));
     $_SESSION['user']->setProfile($newInfo);
     $username = $_SESSION['user']->getUsername();
     $this->dal->updateUser($username, $newInfo);
 }
 /**
  * Verifies login data stored in cookies.
  * 
  * @param  String $cookieName        Username stored in cookie.
  * @param  String $cookiePassword    Password stored in cookie.
  *
  * @throws LWrongCookieInformationException  When user does not exist in database, or if user exist 
  *                                           but password does not match.
  */
 public function verifyPersistentLogin($cookieName, $cookiePassword)
 {
     if (!$this->dal->findUserByUsername($cookieName)) {
         throw new LWrongCookieInformationException();
     } else {
         $user = $this->dal->findUserByUsername($cookieName);
         if (base64_encode($user->getPassword()) == $cookiePassword) {
             if (!isset($_SESSION[self::$loggedIn])) {
                 $_SESSION[self::$loggedIn] = true;
             }
         } else {
             throw new LWrongCookieInformationException();
         }
     }
 }
Example #4
0
 /**
  * Search for input username in the database.
  *
  * @param  String $username 	Input search term.
  *
  * @throws SUsernameMissingException	When search field is empty.
  * @throws SInvalidCharactersException	When $username contains invalid characters.
  */
 public function searchUser($username)
 {
     if (strlen($username) < 1) {
         throw new SUsernameMissingException();
     } else {
         if (preg_match("/^[0-9A-Za-z_]+\$/", $username) == 0) {
             throw new SInvalidCharactersException();
         } else {
             $this->searchResult = $this->dal->searchForUser($username);
             if ($this->searchResult instanceof User) {
                 $this->foundMatch = true;
             } else {
                 $this->foundMatch = false;
             }
         }
     }
 }
Example #5
0
 public function __construct(\model\UserDAL $userDAL, $username, $password)
 {
     $shaPassword = sha1(\Settings::SALT . $password);
     if (is_string($username) == false || is_string($password) == false || strlen($username) < 1 && strlen($password) < 1) {
         throw new EmptyInputException();
     }
     if (is_string($username) == false || strlen($username) < 1) {
         throw new NoUserNameException();
     }
     if (strip_tags($username) != $username) {
         throw new InvalidCharacters();
     }
     if (is_string($password) == false || strlen($password) < 1) {
         throw new NoPasswordException();
     }
     if (!$userDAL->checkUserCredentials($username, $shaPassword)) {
         throw new WrongUserCredentialsException();
     }
     $this->username = $username;
     $this->password = $shaPassword;
 }