Ejemplo n.º 1
0
 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());
 }
Ejemplo 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);
Ejemplo 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');
Ejemplo n.º 4
0
 public function testSetTwoFactorAuthHelper()
 {
     $twoFactorHelperStub = $this->getMock('\\pmill\\Auth\\Interfaces\\TwoFactorAuthenticationHelper');
     $twoFactorHelperStub->method('required')->willReturn(true);
     $twoFactorHelperStub->method('verify')->willReturn(true);
     $auth = new \pmill\Auth\Authenticate();
     $auth->setTwoFactorAuthHelper($twoFactorHelperStub);
     $this->assertInstanceOf('\\pmill\\Auth\\Interfaces\\TwoFactorAuthenticationHelper', $auth->getTwoFactorAuthHelper());
 }