1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<?php
namespace Psso\Challenge;
use Psso\{Challenge, ChallengeResult, Input, AuthProvider, AuthInterface};
class Password extends Challenge {
public function getInputs(): array {
if (isset($this->context->user)) {
return [
new Input('password', Input::SECRET, 'challenge.input.password')
];
}
return [
new Input('username', Input::TEXT, 'challenge.input.username'),
new Input('password', Input::SECRET, 'challenge.input.password'),
];
}
public function validate(
AuthProvider $provider, array $inputData
): ChallengeResult {
self::requireInterface($provider, AuthInterface\Password::class);
$successful = $provider->validatePassword(
$inputData['username'] ?? $this->context->user,
$inputData['password']
);
return new ChallengeResult(
self::class, $successful, $inputData['username'] ?? null,
$successful ? null : 'challenge.message.wrong-password'
);
}
}
|