genwikihash.php
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| genwikihash.php [2006/11/09 19:04] – old revision restored andi | genwikihash.php [2006/11/13 13:48] (current) – old revision restored andi | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | From command line (using php-cli): | ||
| + | < | ||
| + | $ php genWikihash.php <clear text pass> [<crypt method (defaults to smd5)>] | ||
| + | </ | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | // call it: php dokupass.php <clear text pass> <method (default smd5)> | ||
| + | // Tomas V.V.Cox < | ||
| + | |||
| + | function msg($str) { die($str); } | ||
| + | |||
| + | /** | ||
| + | * Encrypts a password using the given method and salt | ||
| + | * | ||
| + | * If the selected method needs a salt and none was given, a random one | ||
| + | * is chosen. | ||
| + | * | ||
| + | * The following methods are understood: | ||
| + | * | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | * | ||
| + | * @author | ||
| + | * @return | ||
| + | */ | ||
| + | function auth_cryptPassword($clear, | ||
| + | global $conf; | ||
| + | if(empty($method)) $method = $conf[' | ||
| + | |||
| + | //prepare a salt | ||
| + | if(empty($salt)) $salt = md5(uniqid(rand(), | ||
| + | |||
| + | switch(strtolower($method)){ | ||
| + | case ' | ||
| + | return crypt($clear,' | ||
| + | case ' | ||
| + | return md5($clear); | ||
| + | case ' | ||
| + | return sha1($clear); | ||
| + | case ' | ||
| + | $salt=substr($salt, | ||
| + | return ' | ||
| + | case ' | ||
| + | return crypt($clear, | ||
| + | case ' | ||
| + | //from http:// | ||
| + | $nr=0x50305735; | ||
| + | $nr2=0x12345671; | ||
| + | $add=7; | ||
| + | $charArr = preg_split("//", | ||
| + | foreach ($charArr as $char) { | ||
| + | if (($char == '' | ||
| + | $charVal = ord($char); | ||
| + | $nr ^= ((($nr & 63) + $add) * $charVal) + ($nr << 8); | ||
| + | $nr2 += ($nr2 << 8) ^ $nr; | ||
| + | $add += $charVal; | ||
| + | } | ||
| + | return sprintf(" | ||
| + | case ' | ||
| + | return ' | ||
| + | default: | ||
| + | msg(" | ||
| + | } | ||
| + | } | ||
| + | if (empty($_SERVER[' | ||
| + | die(" | ||
| + | } | ||
| + | $method = !empty($_SERVER[' | ||
| + | echo auth_cryptPassword($_SERVER[' | ||
| + | |||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | |||
| + | == Comments == | ||
| + | |||
| + | Roland Eckert wrote 2006-Aug-06 16:41:16 CET: | ||
| + | |||
| + | I also had luck generating a valid hash using the command line | ||
| + | |||
| + | <code php> | ||
| + | php -r 'echo md5(" | ||
| + | </ | ||
| + | |||
