| 1 |
<?php |
| 2 |
|
| 3 |
namespace Intervention\HttpAuth\Vault; |
| 4 |
|
| 5 |
use Intervention\HttpAuth\AbstractVault; |
| 6 |
use Intervention\HttpAuth\Directive; |
| 7 |
use Intervention\HttpAuth\Key; |
| 8 |
|
| 9 |
class BasicVault extends AbstractVault |
| 10 |
{ |
| 11 |
/** |
| 12 |
* Determine if given key is able to unlock (access) vault. |
| 13 |
* |
| 14 |
* @param Key $key |
| 15 |
* @return bool |
| 16 |
*/ |
| 17 |
public function unlocksWithKey(Key $key): bool |
| 18 |
{ |
| 19 |
$username_match = $this->getUsername() == $key->getUsername(); |
| 20 |
$password_match = $this->getPassword() == $key->getPassword(); |
| 21 |
|
| 22 |
return $username_match && $password_match; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Return auth directive |
| 27 |
* |
| 28 |
* @return Directive |
| 29 |
*/ |
| 30 |
public function getDirective(): Directive |
| 31 |
{ |
| 32 |
return new Directive('basic', [ |
| 33 |
'realm' => $this->getRealm(), |
| 34 |
'charset' => 'UTF-8', |
| 35 |
]); |
| 36 |
} |
| 37 |
} |
| 38 |
|