Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 21 |
App\Models\BasicAuth | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 21 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
authenticate | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 13 |
|||
setAuthHeaders | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
<?php | |
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
namespace App\Models; | |
/** | |
* Description of BasicAuth | |
* | |
* @author lennartbinscheck | |
*/ | |
class BasicAuth { | |
private $users = []; | |
private $serverPhpUserAuth; | |
private $serverPhpAuthPw; | |
public function __construct() { | |
$this->serverPhpUserAuth = $_SERVER["PHP_AUTH_USER"]; | |
$this->serverPhpAuthPw = $_SERVER['PHP_AUTH_PW']; | |
$this->users = ["björn" => "björn", "lennart" => "lennart"]; | |
$this->authenticate(); | |
} | |
private function authenticate() { | |
if (!isset($this->serverPhpUserAuth)) { | |
$this->setAuthHeaders(); | |
echo "Credentials are required to access the webpage!"; | |
exit; | |
} else { | |
if (!array_key_exists($this->serverPhpUserAuth, $this->users) || | |
$this->users[$this->serverPhpUserAuth] !== $this->serverPhpAuthPw) { | |
$this->setAuthHeaders(); | |
echo "Improper credentials"; | |
exit; | |
} | |
} | |
} | |
private function setAuthHeaders() { | |
header('WWW-Authenticate: Basic realm="Azubis Only"'); | |
header('HTTP/1.0 401 Unauthorized'); | |
} | |
} |