public function getUserFromDatabase(\model\UserCredentials $uc)
 {
     $smt = $this->conn->prepare("SELECT * FROM " . self::$table . " WHERE " . self::$colUsername . "=?");
     if ($smt->execute([$uc->getName()])) {
         return $smt->fetchObject();
     }
 }
Example #2
0
 public function MatchRecord(\model\UserCredentials $credentials) : \bool
 {
     //Clean up the table by removing old passphrases
     $delete = $this->db->prepare("DELETE FROM " . self::$table . " WHERE " . self::$columnExpiration . " < NOW()");
     $delete->execute();
     $stmt = $this->db->prepare("SELECT * FROM " . self::$table . " WHERE " . self::$columnUsername . " = ? AND " . self::$columnPassphrase . " = ? AND " . self::$columnExpiration . " > ?");
     $stmt->execute(array($credentials->GetUsername(), $credentials->GetPassword(), date('Y-m-d H:i:s')));
     return $stmt->rowCount() == 1;
 }
Example #3
0
 public function UserExists(\model\UserCredentials $uc) : \bool
 {
     foreach ($this->GetAllUsers() as $entry) {
         /* @var $entry \model\UserCredentials */
         if ($entry->GetUsername() == $uc->GetUsername()) {
             return true;
         }
     }
     return false;
 }
Example #4
0
 public static function MatchRecord(\model\UserCredentials $credentials) : \bool
 {
     $file_handle = fopen(self::$logfile, "r");
     while (!feof($file_handle)) {
         $line = fgets($file_handle);
         $data = explode(self::$dataDelimiter, $line);
         if ($data[self::$username] == $credentials->GetUsername() && $data[self::$passPhrase] == $credentials->GetPassword() && $data[self::$expiration] > time()) {
             fclose($file_handle);
             return true;
         }
     }
     fclose($file_handle);
     return false;
 }
Example #5
0
 public function AuthenticateLogin(\model\UserCredentials $credentials) : \bool
 {
     foreach ($this->userDal->GetAllUsers() as $entry) {
         /* @var $entry \model\UserCredentials */
         if ($entry->GetUsername() == $credentials->GetUsername() && password_verify($credentials->GetPassword(), $entry->GetPassword())) {
             $this->LoginUser($credentials);
             return true;
         }
     }
     if ($this->persistentLoginDAL->MatchRecord($credentials)) {
         $this->LoginUser($credentials);
         return true;
     }
     return false;
 }
 public function tryLoginUser(UserCredentials $toLogin)
 {
     $registered = $this->userDAL->getUserByName($toLogin->getUsername());
     $tempPassword = $this->tempDAL->getTempPassword($toLogin->getUsername());
     $loginByPostCredentials = password_verify($toLogin->getPassword(), $registered->getPassword());
     $loginByCookies = $tempPassword != "" && $tempPassword === $toLogin->getCookiePassword();
     if (!$loginByPostCredentials && !$loginByCookies) {
         throw new \WrongCredentialsException("Wrong credentials");
     }
     $this->loginUser($toLogin);
 }
Example #7
0
 public function AuthenticateLogin(\model\UserCredentials $credentials) : \bool
 {
     return $credentials->GetUsername() === self::$username && $credentials->GetPassword() === self::$password || dal\PersistentLoginDAL::MatchRecord($credentials);
 }