2 // PukiWiki - Yet another WikiWikiWeb clone.
4 // Copyright 2001-2018 PukiWiki Development Team
5 // License: GPL v2 or (at your option) any later version
7 // MD5 plugin: Allow to convert password/passphrase
8 // * PHP sha1() -- If you have sha1() or mhash extension
10 // * PHP hash('sha256')
11 // * PHP hash('sha512')
12 // * LDAP SHA / SSHA -- If you have sha1() or mhash extension
15 // User interface of pkwk_hash_compute() for system admin
16 function plugin_md5_action()
19 if (PKWK_SAFE_MODE || PKWK_READONLY) die_message('Prohibited by admin');
21 $phrase = isset($post['phrase']) ? $post['phrase'] : '';
24 // If plugin=md5&md5=password, only set it (Don't compute)
25 $value = isset($get['md5']) ? $get['md5'] : '';
27 'msg' =>'Compute userPassword',
28 'body'=>plugin_md5_show_form(isset($post['phrase']), $value));
30 // Compute (Don't show its $phrase at the same time)
31 $is_output_prefix = isset($post['prefix']);
32 $salt = isset($post['salt']) ? $post['salt'] : '';
33 $scheme = isset($post['scheme']) ? $post['scheme']: '';
34 $algos_enabled = plugin_md5_get_algos_enabled();
35 $scheme_list = array('x-php-md5', 'MD5', 'SMD5');
36 if ($algos_enabled->sha1) {
37 array_push($scheme_list, 'x-php-sha1', 'SHA', 'SSHA');
39 if ($algos_enabled->sha256) {
40 array_push($scheme_list, 'x-php-sha256', 'SHA256', 'SSHA256');
42 if ($algos_enabled->sha512) {
43 array_push($scheme_list, 'x-php-sha512', 'SHA512', 'SSHA512');
45 if (!in_array($scheme, $scheme_list)) {
48 'body' => 'Invalid scheme: ' . htmlsc($scheme),
51 $scheme_with_salt = '{' . $scheme . '}' . $salt;
55 pkwk_hash_compute($phrase, $scheme_with_salt,
56 $is_output_prefix, TRUE));
60 // $nophrase = Passphrase is (submitted but) empty
61 // $value = Default passphrase value
62 function plugin_md5_show_form($nophrase = FALSE, $value = '')
64 if (PKWK_SAFE_MODE || PKWK_READONLY) die_message('Prohibited');
65 if (strlen($value) > PKWK_PASSPHRASE_LIMIT_LENGTH) {
66 die_message('Limit: malicious message length');
68 if ($value != '') $value = 'value="' . htmlsc($value) . '" ';
69 $algos_enabled = plugin_md5_get_algos_enabled();
70 $sha1_checked = $md5_checked = '';
71 if ($algos_enabled->sha1) {
72 $sha1_checked = 'checked="checked" ';
74 $md5_checked = 'checked="checked" ';
76 $self = get_base_uri();
78 <p><strong>NOTICE: Don't use this feature via untrustful or unsure network</strong></p>
81 if ($nophrase) $form .= '<strong>NO PHRASE</strong><br />';
83 <form action="$self" method="post">
85 <input type="hidden" name="plugin" value="md5" />
86 <label for="_p_md5_phrase">Phrase:</label>
87 <input type="text" name="phrase" id="_p_md5_phrase" size="60" $value/><br />
90 <input type="radio" name="scheme" id="_p_md5_md5" value="x-php-md5" />
91 <label for="_p_md5_md5">PHP md5</label><br />
93 if ($algos_enabled->sha1) $form .= <<<EOD
94 <input type="radio" name="scheme" id="_p_md5_sha1" value="x-php-sha1" />
95 <label for="_p_md5_sha1">PHP sha1</label><br />
97 if ($algos_enabled->sha256) $form .= <<<EOD
98 <input type="radio" name="scheme" id="_p_md5_sha256" value="x-php-sha256" />
99 <label for="_p_md5_sha256">PHP sha256</label><br />
101 if ($algos_enabled->sha512) $form .= <<<EOD
102 <input type="radio" name="scheme" id="_p_md5_sha512" value="x-php-sha512" />
103 <label for="_p_md5_sha512">PHP sha512</label><br />
105 if ($algos_enabled->sha1) $form .= <<<EOD
106 <input type="radio" name="scheme" id="_p_md5_lssha" value="SSHA" $sha1_checked/>
107 <label for="_p_md5_lssha">LDAP SSHA (sha-1 with a seed) *</label><br />
108 <input type="radio" name="scheme" id="_p_md5_lsha" value="SHA" />
109 <label for="_p_md5_lsha">LDAP SHA (sha-1)</label><br />
112 <input type="radio" name="scheme" id="_p_md5_lsmd5" value="SMD5" $md5_checked/>
113 <label for="_p_md5_lsmd5">LDAP SMD5 (md5 with a seed) *</label><br />
114 <input type="radio" name="scheme" id="_p_md5_lmd5" value="MD5" />
115 <label for="_p_md5_lmd5">LDAP MD5</label><br />
117 if ($algos_enabled->sha256) $form .= <<<EOD
118 <input type="radio" name="scheme" id="_p_md5_lssha256" value="SSHA256"/>
119 <label for="_p_md5_lssha256">LDAP SSHA256 (sha256 with a seed) *</label><br />
120 <input type="radio" name="scheme" id="_p_md5_lsha256" value="SHA256" />
121 <label for="_p_md5_lsha256">LDAP SHA256</label><br />
123 if ($algos_enabled->sha512) $form .= <<<EOD
124 <input type="radio" name="scheme" id="_p_md5_lssha512" value="SSHA512"/>
125 <label for="_p_md5_lssha512">LDAP SSHA512 (sha512 with a seed) *</label><br />
126 <input type="radio" name="scheme" id="_p_md5_lsha512" value="SHA512" />
127 <label for="_p_md5_lsha512">LDAP SHA512</label><br />
130 <input type="checkbox" name="prefix" id="_p_md5_prefix" checked="checked" />
131 <label for="_p_md5_prefix">Add scheme prefix (RFC2307, Using LDAP as NIS)</label><br />
133 <label for="_p_md5_salt">Salt:</label>
134 <input type="text" name="salt" id="_p_md5_salt" size="60" /><br />
136 <input type="submit" value="Compute" /><br />
139 <p>* = Salt enabled<p/>
148 * Get availabilites of algos.
150 function plugin_md5_get_algos_enabled()
152 $sha1_enabled = function_exists('sha1');
153 $sha256_enabled = false;
154 $sha512_enabled = false;
155 if (function_exists('hash') && function_exists('hash_algos')) {
156 $algos = hash_algos();
157 if (in_array('sha256', $algos)) {
158 $sha256_enabled = true;
160 if (in_array('sha512', $algos)) {
161 $sha512_enabled = true;
164 return (object) array(
165 'sha1' => $sha1_enabled,
166 'sha256' => $sha256_enabled,
167 'sha512' => $sha512_enabled,