昨天装了一个Typecho,今天登录的时候发现密码忘记了==!(是有多老这么健忘),然后稍微看了一下Typecho生成密码的代码。改写了如下这么一段脚本可以重新生成你想要的密码,然后把生成的字符串替换数据中typecho_users表的password字段即可。 <?php namespace test; function hash($string, $salt = NULL) { $salt = empty($salt) ? \test\randString(9) : $salt; $length = strlen($string); $hash = ''; $last = ord($string[$length - 1]); $pos = 0;
/** 判断扰码长度 */ if (strlen($salt) != 9) { /** 如果不是9直接返回 */ return; }
while ($pos < $length) { $asc = ord($string[$pos]); $last = ($last * ord($salt[($last % $asc) % 9]) + $asc) % 95 + 32; $hash .= chr($last); $pos ++; }
return '$T$' . $salt . md5($hash); } function randString($length, $specialChars = false) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; if ($specialChars) { $chars .= '!@#$%^&*()'; }
$result = ''; $max = strlen($chars) - 1; for ($i = 0; $i < $length; $i++) { $result .= $chars[rand(0, $max)]; } return $result; } // The password u wanna use $password = '123456'; var_dump(\test\hash($password));
查看更多关于Typecho 0.9忘记密码重置脚本的详细内容...