2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: md5.inc.php,v 1.8 2005/03/28 14:23:41 henoheno Exp $
6 define('PLUGIN_MD5_LIMIT_LENGTH', 512);
8 function plugin_md5_action()
12 if (PKWK_SAFE_MODE || PKWK_READONLY) die_message('Prohibited');
15 $key = isset($post['key']) ? $post['key'] : '';
16 $submit = isset($post['key']);
18 // Compute (Don't show its $key at the same time)
19 $scheme = isset($post['scheme']) ? $post['scheme'] : '';
20 $prefix = isset($post['prefix']);
21 $body = plugin_md5_compute($scheme, $key, $prefix);
22 return array('msg'=>'MD5', 'body'=>$body);
25 // If plugin=md4&md5=password, only set it (Don't compute)
26 $value = isset($get['md5']) ? $get['md5'] : '';
28 plugin_md5_checklimit($value);
29 if ($value != '') $value = 'value="' . htmlspecialchars($value) . '" ';
30 $self = get_script_uri();
32 if ($submit) $form .= '<strong>NO PHRASE</strong><br />';
34 <form action="$self" method="post">
36 <input type="hidden" name="plugin" value="md5" />
37 <label for="_p_md5_phrase">Phrase:</label>
38 <input type="text" name="key" id="_p_md5_phrase" size="30" $value/><br />
39 <input type="radio" name="scheme" id="_p_md5_sha1" value="php_sha1" />
40 <label for="_p_md5_sha1">PHP sha1()</label><br />
41 <input type="radio" name="scheme" id="_p_md5_md5" value="php_md5" checked="checked" />
42 <label for="_p_md5_md5">PHP md5()</label><br />
43 <input type="radio" name="scheme" id="_p_md5_crpt" value="php_crypt" />
44 <label for="_p_md5_crpt">PHP crypt()</label><br />
45 <input type="radio" name="scheme" id="_p_md5_lmd5" value="ldap_md5" />
46 <label for="_p_md5_lmd5">OpenLDAP MD5</label><br />
47 <input type="radio" name="scheme" id="_p_md5_lsha" value="ldap_sha" />
48 <label for="_p_md5_lsha">OpenLDAP SHA (sha1)</label><br />
49 <input type="checkbox" name="prefix" id="_p_md5_prefix" checked="checked" />
50 <label for="_p_md5_prefix">Add scheme prefix (RFC2307, Using LDAP as NIS)</label><br />
51 <input type="submit" value="Compute" />
55 return array('msg'=>'MD5', 'body'=>$form);
59 // Compute hash with php-functions, or compute like slappasswd (OpenLDAP)
60 function plugin_md5_compute($scheme = 'php_md5', $key = '', $prefix = FALSE)
62 plugin_md5_checklimit($key);
64 switch (strtolower($scheme)) {
65 case 'x-php-crypt' : /* FALLTHROUGH */
67 $hash = ($prefix ? '{x-php-crypt}' : '') . crypt($key); break;
68 case 'x-php-md5' : /* FALLTHROUGH */
70 $hash = ($prefix ? '{x-php-md5}' : '') . md5($key); break;
71 case 'x-php-sha1' : /* FALLTHROUGH */
73 $hash = ($prefix ? '{x-php-sha1}' : '') . sha1($key); break;
74 case 'md5' : /* FALLTHROUGH */
76 $hash = ($prefix ? '{MD5}' : '') . base64_encode(hex2bin(md5($key))); break;
77 case 'sha' : /* FALLTHROUGH */
79 $hash = ($prefix ? '{SHA}' : '') . base64_encode(hex2bin(sha1($key))); break;
80 default: $hash = ''; break;
86 function plugin_md5_checklimit($text)
88 if (strlen($text) > PLUGIN_MD5_LIMIT_LENGTH)
89 die_message('Limit: malicious message length');