1 | <?php |
||
2 | /** |
||
3 | * Displays form for password change |
||
4 | */ |
||
5 | |||
6 | declare(strict_types=1); |
||
7 | |||
8 | namespace PhpMyAdmin\Display; |
||
9 | |||
10 | use PhpMyAdmin\Relation; |
||
11 | use PhpMyAdmin\RelationCleanup; |
||
12 | use PhpMyAdmin\Server\Privileges; |
||
13 | use PhpMyAdmin\Template; |
||
14 | use PhpMyAdmin\Util; |
||
15 | |||
16 | /** |
||
17 | * Displays form for password change |
||
18 | */ |
||
19 | class ChangePassword |
||
20 | { |
||
21 | /** |
||
22 | * Get HTML for the Change password dialog |
||
23 | * |
||
24 | * @param string $mode where is the function being called? |
||
25 | * values : 'change_pw' or 'edit_other' |
||
26 | * @param string $username username |
||
27 | * @param string $hostname hostname |
||
28 | * |
||
29 | * @return string html snippet |
||
30 | */ |
||
31 | 4 | public static function getHtml($mode, $username, $hostname) |
|
32 | { |
||
33 | 4 | $relation = new Relation($GLOBALS['dbi']); |
|
34 | 4 | $serverPrivileges = new Privileges( |
|
35 | 4 | new Template(), |
|
36 | 4 | $GLOBALS['dbi'], |
|
37 | 3 | $relation, |
|
38 | 4 | new RelationCleanup($GLOBALS['dbi'], $relation) |
|
39 | ); |
||
40 | |||
41 | /** |
||
42 | * autocomplete feature of IE kills the "onchange" event handler and it |
||
43 | * must be replaced by the "onpropertychange" one in this case |
||
44 | */ |
||
45 | 4 | $chg_evt_handler = 'onchange'; |
|
46 | |||
47 | 4 | $is_privileges = isset($_REQUEST['route']) && $_REQUEST['route'] === '/server/privileges'; |
|
48 | |||
49 | 4 | $template = new Template(); |
|
50 | 4 | $html = $template->render('display/change_password/file_a', [ |
|
51 | 4 | 'is_privileges' => $is_privileges, |
|
52 | 4 | 'username' => $username, |
|
53 | 4 | 'hostname' => $hostname, |
|
54 | 4 | 'chg_evt_handler' => $chg_evt_handler, |
|
55 | ]); |
||
56 | |||
57 | 4 | $serverType = Util::getServerType(); |
|
58 | 4 | $serverVersion = $GLOBALS['dbi']->getVersion(); |
|
59 | 4 | $orig_auth_plugin = $serverPrivileges->getCurrentAuthenticationPlugin( |
|
60 | 4 | 'change', |
|
61 | 3 | $username, |
|
62 | 3 | $hostname |
|
63 | ); |
||
64 | |||
65 | 4 | $isNew = ($serverType == 'MySQL' && $serverVersion >= 50507) |
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
66 | 4 | || ($serverType == 'MariaDB' && $serverVersion >= 50200); |
|
67 | |||
68 | 4 | if ($isNew) { |
|
69 | // Provide this option only for 5.7.6+ |
||
70 | // OR for privileged users in 5.5.7+ |
||
71 | 4 | if (($serverType == 'MySQL' |
|
72 | 4 | && $serverVersion >= 50706) |
|
73 | 4 | || ($GLOBALS['dbi']->isSuperuser() && $mode == 'edit_other') |
|
74 | ) { |
||
75 | 4 | $active_auth_plugins = $serverPrivileges->getActiveAuthPlugins(); |
|
76 | 4 | if (isset($active_auth_plugins['mysql_old_password'])) { |
|
77 | unset($active_auth_plugins['mysql_old_password']); |
||
78 | } |
||
79 | |||
80 | 4 | $html .= $template->render('display/change_password/file_b', [ |
|
81 | 4 | 'active_auth_plugins' => $active_auth_plugins, |
|
82 | 4 | 'orig_auth_plugin' => $orig_auth_plugin, |
|
83 | ]); |
||
84 | } else { |
||
85 | 4 | $html .= $template->render('display/change_password/file_c'); |
|
86 | } |
||
87 | } else { |
||
88 | $active_auth_plugins = ['mysql_native_password' => __('Native MySQL authentication')]; |
||
89 | |||
90 | $html .= $template->render('display/change_password/file_d', [ |
||
91 | 'orig_auth_plugin' => $orig_auth_plugin, |
||
92 | 'active_auth_plugins' => $active_auth_plugins, |
||
93 | ]); |
||
94 | } |
||
95 | |||
96 | 4 | $html .= $template->render('display/change_password/file_e'); |
|
97 | |||
98 | 4 | return $html; |
|
99 | } |
||
100 | } |
||
101 |