Exemplo n.º 1
0
 public function onAuthenticate(\Zend\Authentication\Event\Authenticate $event)
 {
     $result = $event->getResult();
     if ($result->isValid()) {
         $prevResult = $event->getPreviousResult();
         $identity = $result->getIdentity();
         if ($prevResult !== null) {
             $identity = $prevResult->getIdentity();
         }
         if (isset($identity['do2fa']) && $identity['do2fa']) {
             $twoFactorResponse = $event->getParam('twoFactorResponse');
             if (isset($twoFactorResponse)) {
                 if ($prevResult !== null && isset($prevResult->twoFactorToken) && $twoFactorResponse === $prevResult->twoFactorToken) {
                     $result = new \Zend\Authentication\Result(\Zend\Authentication\Result::SUCCESS, $identity);
                     $event->setResult($result);
                     return $result;
                 }
             }
             $result = new \Zend\Authentication\Result(-4, $identity, 'Requires 2 factor Auth');
             $result->twoFactorToken = 'efg456';
             //generate randomly
             $event->setResult($result);
             $event->stopPropagation();
             return $result;
         }
     }
     return $result;
 }
 public function onAuthenticate(\Zend\Authentication\Event\Authenticate $event)
 {
     $identity = $event->getParam('identity');
     if ($identity !== null) {
         if ($this->getFailurecount($identity) > 2) {
             $result = new \Zend\Authentication\Result(-4, $identity, 'Too many failed attempts');
             $event->setResult($result);
             $event->stopPropagation();
             return $result;
         }
     }
     $ip = $event->getParam('ip');
     if ($ip !== null) {
         if ($this->getFailurecount($ip) > 2) {
             $result = new \Zend\Authentication\Result(-4, $ip, 'Too many failed attempts');
             $event->setResult($result);
             $event->stopPropagation();
             return $result;
         }
     }
 }