저자: Nick Sagona, III (nick@popphp.org)
예제 #1
0
 /**
  * Set the field values
  *
  * @param  array           $values
  * @param  \Pop\Auth\Auth  $auth
  * @return Login
  */
 public function setFieldValues(array $values = null, Auth $auth = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->username && null !== $this->password && null !== $auth && !empty($this->role_id)) {
         $auth->authenticate(html_entity_decode($this->username, ENT_QUOTES, 'UTF-8'), html_entity_decode($this->password, ENT_QUOTES, 'UTF-8'));
         if (!$auth->isValid()) {
             $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'The login was not correct.'));
         } else {
             if (!$auth->adapter()->getUser()->verified) {
                 $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is not verified.'));
             } else {
                 if (!$auth->adapter()->getUser()->active) {
                     $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is blocked.'));
                 } else {
                     if ($this->role_id != $auth->adapter()->getUser()->role_id) {
                         $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'The login was not correct.'));
                     } else {
                         $role = Table\Roles::findById($auth->adapter()->getUser()->role_id);
                         if (isset($role->id) && null !== $role->permissions) {
                             $permissions = unserialize($role->permissions);
                             if (isset($permissions['deny'])) {
                                 foreach ($permissions['deny'] as $deny) {
                                     if ($deny['resource'] == 'member-login') {
                                         $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is not allowed to login.'));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
예제 #2
0
 /**
  * Set the field values
  *
  * @param  array  $values
  * @param  Auth   $auth
  * @return Login
  */
 public function setFieldValues(array $values = null, Auth $auth = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->username && null !== $this->password && null !== $auth) {
         $auth->authenticate(html_entity_decode($this->username, ENT_QUOTES, 'UTF-8'), html_entity_decode($this->password, ENT_QUOTES, 'UTF-8'));
         if (!$auth->isValid()) {
             $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'The login was not correct.'));
         } else {
             if (!$auth->adapter()->getUser()->verified) {
                 $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is not verified.'));
             } else {
                 if (!$auth->adapter()->getUser()->active) {
                     $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, 'That user is blocked.'));
                 }
             }
         }
     }
     return $this;
 }
예제 #3
0
 public function testPasswordEncryption()
 {
     $a = new Auth(new File(__DIR__ . '/../tmp/access.txt'), Auth::ENCRYPT_MD5);
     $a->authenticate('testuser1', '12test34');
     $this->assertFalse($a->isValid());
     unset($a);
     $a = new Auth(new File(__DIR__ . '/../tmp/access.txt'), Auth::ENCRYPT_SHA1);
     $a->authenticate('testuser1', '12test34');
     $this->assertFalse($a->isValid());
     unset($a);
     $a = new Auth(new File(__DIR__ . '/../tmp/access.txt'), Auth::ENCRYPT_CRYPT, array('salt' => 'abcdefg'));
     $a->authenticate('testuser1', '12test34');
     $this->assertFalse($a->isValid());
 }
예제 #4
0
 /**
  * Constructor
  *
  * Instantiate the auth object
  *
  * @param int    $encryption
  * @param string $salt
  * @return \Phire\Auth\Auth
  */
 public function __construct($encryption = 0, $salt = null)
 {
     $adapter = new A\Adapter\Table('Phire\\Table\\Users', 'username', 'password', 'role_id');
     parent::__construct($adapter, $encryption);
 }
예제 #5
0
파일: auth2.php 프로젝트: nicksagona/PopPHP
<?php

require_once '../../bootstrap.php';
use Pop\Auth;
try {
    // Set the username and password
    $username = '******';
    $password = '******';
    // Create auth object
    $auth = new Auth\Auth(new Auth\Adapter\File('../assets/files/access-crypt.txt'), Auth\Auth::ENCRYPT_CRYPT);
    // Define some other auth parameters and authenticate the user
    $auth->setAttemptLimit(3)->setAttempts(2)->setAllowedIps('127.0.0.1')->authenticate($username, $password);
    echo $auth->getResultMessage() . '<br /> ' . PHP_EOL;
    // Check if the auth attempt is valid
    if ($auth->isValid()) {
        // The user is valid so do top-secret stuff
    }
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
예제 #6
0
 /**
  * Constructor
  *
  * Instantiate the auth object
  *
  * @param int    $encryption
  * @param string $salt
  */
 public function __construct($encryption = Authentication\Auth::ENCRYPT_MD5, $salt = null)
 {
     $adapter = new Authentication\Adapter\Table('LaceCart\\Backend\\Admin', $encryption);
     $adapter->setUsernameField('email')->setPasswordField('password');
     parent::__construct($adapter, $encryption);
 }