Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
33 / 33
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PasswordAuthenticationRequest
100.00% covered (success)
100.00%
33 / 33
100.00% covered (success)
100.00%
2 / 2
8
100.00% covered (success)
100.00%
1 / 1
 getFieldInfo
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
7
 describeCredentials
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * @license GPL-2.0-or-later
4 * @file
5 */
6
7namespace MediaWiki\Auth;
8
9use MediaWiki\Language\RawMessage;
10
11/**
12 * This is a value object for authentication requests with a username and password
13 *
14 * @stable to extend
15 * @ingroup Auth
16 * @since 1.27
17 */
18class PasswordAuthenticationRequest extends AuthenticationRequest {
19    /** @var string|null */
20    public $password = null;
21
22    /** @var string|null Password, again */
23    public $retype = null;
24
25    /**
26     * @inheritDoc
27     * @stable to override
28     */
29    public function getFieldInfo() {
30        if ( $this->action === AuthManager::ACTION_REMOVE ) {
31            return [];
32        }
33
34        // for password change it's nice to make extra clear that we are asking for the new password
35        $forNewPassword = $this->action === AuthManager::ACTION_CHANGE;
36        $passwordLabel = $forNewPassword ? 'newpassword' : 'userlogin-yourpassword';
37        $retypeLabel = $forNewPassword ? 'retypenew' : 'yourpasswordagain';
38
39        $ret = [
40            'username' => [
41                'type' => 'string',
42                'label' => wfMessage( 'userlogin-yourname' ),
43                'help' => wfMessage( 'authmanager-username-help' ),
44            ],
45            'password' => [
46                'type' => 'password',
47                'label' => wfMessage( $passwordLabel ),
48                'help' => wfMessage( 'authmanager-password-help' ),
49                'sensitive' => true,
50            ],
51        ];
52
53        switch ( $this->action ) {
54            case AuthManager::ACTION_CHANGE:
55            case AuthManager::ACTION_REMOVE:
56                unset( $ret['username'] );
57                break;
58        }
59
60        if ( $this->action !== AuthManager::ACTION_LOGIN ) {
61            $ret['retype'] = [
62                'type' => 'password',
63                'label' => wfMessage( $retypeLabel ),
64                'help' => wfMessage( 'authmanager-retype-help' ),
65                'sensitive' => true,
66            ];
67        }
68
69        return $ret;
70    }
71
72    /**
73     * @inheritDoc
74     * @stable to override
75     */
76    public function describeCredentials() {
77        return [
78            'provider' => wfMessage( 'authmanager-provider-password' ),
79            'account' => new RawMessage( '$1', [ $this->username ] ),
80        ];
81    }
82}