public function testCorrectSecret()
 {
     $user = $this->getMockBuilder('\\pmill\\Auth\\Interfaces\\AuthUser')->getMock();
     $user->method('getAuthId')->willReturn(1);
     $user->method('getAuthPassword')->willReturn($this->correctHashedPassword);
     $user->method('getTwoFactorSecret')->willReturn('abcdef123456');
     $auth = new \pmill\Auth\Authenticate();
     $auth->login($user, $this->rawPassword, 'abcdef123456');
     $this->assertEquals(1, $auth->getLoggedInUserId());
 }
Esempio n. 2
0
<?php

require_once '../vendor/autoload.php';
require_once 'PasswordUser.php';
$output = [];
$user = new examples\PasswordUser();
$user->setId(1);
$user->setUsername('username');
$user->setPassword('hunter2');
$auth = new \pmill\Auth\Authenticate();
$auth->setMaxAttempts(3);
/**
 * Attempt login with correct password
 */
$auth->login($user, 'hunter2');
$output[] = 'successful login';
$auth->logout();
/**
 * Attempt login with incorrect password
 */
try {
    $auth->login($user, 'incorrect-password');
} catch (\pmill\Auth\Exceptions\PasswordException $e) {
    $output[] = 'login failed, incorrect password';
}
/**
 * Expected output:
 * successful login
 * login failed, incorrect password
 */
print_r($output);
Esempio n. 3
0
<?php

require_once '../vendor/autoload.php';
require_once 'TwoAuthUser.php';
$output = [];
$user = new examples\TwoAuthUser();
$user->setId(1);
$user->setUsername('username');
$user->setPassword('hunter2');
$user->setTwoAuthSecret('abcdefg1234567');
$auth = new \pmill\Auth\Authenticate();
$auth->setMaxAttempts(3);
/**
 * Attempt login with correct password and 2fa secret
 */
$auth->login($user, 'hunter2', 'abcdefg1234567');
$output[] = 'successful login';
$auth->logout();
/**
 * Attempt login with incorrect password
 */
try {
    $auth->login($user, 'incorrect-password', 'abcdefg1234567');
} catch (\pmill\Auth\Exceptions\PasswordException $e) {
    $output[] = 'login failed, incorrect password';
}
/**
 * Attempt login with incorrect 2fa secret
 */
try {
    $auth->login($user, 'hunter2', 'incorrect-secret');
Esempio n. 4
0
 public function testSessionKey()
 {
     $authInstances = array();
     for ($i = 1; $i <= 2; $i++) {
         $user = $this->getMockBuilder('\\pmill\\Auth\\Interfaces\\AuthUser')->getMock();
         $user->method('getAuthId')->willReturn($i);
         $user->method('getAuthPassword')->willReturn($this->correctHashedPassword);
         $auth = new \pmill\Auth\Authenticate();
         $auth->setSessionKey('testSessionKey' . $i);
         $auth->login($user, $this->rawPassword);
         $authInstances[$i] = $auth;
     }
     $this->assertEquals('testSessionKey1', $authInstances[1]->getSessionKey());
     $this->assertEquals('testSessionKey2', $authInstances[2]->getSessionKey());
     $this->assertEquals(1, $authInstances[1]->getLoggedInUserId());
     $this->assertEquals(2, $authInstances[2]->getLoggedInUserId());
 }