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 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Auth
20 */
21
22namespace MediaWiki\Auth;
23
24use MediaWiki\Language\RawMessage;
25
26/**
27 * This is a value object for authentication requests with a username and password
28 * @stable to extend
29 * @ingroup Auth
30 * @since 1.27
31 */
32class PasswordAuthenticationRequest extends AuthenticationRequest {
33    /** @var string Password */
34    public $password = null;
35
36    /** @var string Password, again */
37    public $retype = null;
38
39    /**
40     * @inheritDoc
41     * @stable to override
42     */
43    public function getFieldInfo() {
44        if ( $this->action === AuthManager::ACTION_REMOVE ) {
45            return [];
46        }
47
48        // for password change it's nice to make extra clear that we are asking for the new password
49        $forNewPassword = $this->action === AuthManager::ACTION_CHANGE;
50        $passwordLabel = $forNewPassword ? 'newpassword' : 'userlogin-yourpassword';
51        $retypeLabel = $forNewPassword ? 'retypenew' : 'yourpasswordagain';
52
53        $ret = [
54            'username' => [
55                'type' => 'string',
56                'label' => wfMessage( 'userlogin-yourname' ),
57                'help' => wfMessage( 'authmanager-username-help' ),
58            ],
59            'password' => [
60                'type' => 'password',
61                'label' => wfMessage( $passwordLabel ),
62                'help' => wfMessage( 'authmanager-password-help' ),
63                'sensitive' => true,
64            ],
65        ];
66
67        switch ( $this->action ) {
68            case AuthManager::ACTION_CHANGE:
69            case AuthManager::ACTION_REMOVE:
70                unset( $ret['username'] );
71                break;
72        }
73
74        if ( $this->action !== AuthManager::ACTION_LOGIN ) {
75            $ret['retype'] = [
76                'type' => 'password',
77                'label' => wfMessage( $retypeLabel ),
78                'help' => wfMessage( 'authmanager-retype-help' ),
79                'sensitive' => true,
80            ];
81        }
82
83        return $ret;
84    }
85
86    /**
87     * @inheritDoc
88     * @stable to override
89     */
90    public function describeCredentials() {
91        return [
92            'provider' => wfMessage( 'authmanager-provider-password' ),
93            'account' => new RawMessage( '$1', [ $this->username ] ),
94        ];
95    }
96}