花密简介
“花密”提供一种简单的密码管理方法,你只需要记住一个“记忆密码”,为不同的账号设置不同的“区分代号”,然后通过“花密”计算就可以得到不同的复杂密码。
核心代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| <?php
if (isset($_GET["pwd"]) && isset($_GET["key"])) { $pwd = $_GET["pwd"]; $key = $_GET["key"]; $len = isset($_GET["len"]) ? $_GET["len"] : 16;
} else if (isset($_POST["pwd"]) && isset($_POST["key"])) { $pwd = $_POST["pwd"]; $key = $_POST["key"]; $len = isset($_POST["len"]) ? $_POST["len"] : 16; } else { echo ""; exit(0); }
if ($pwd && $key && $len) { $objFP = new FlowerPassword(); $code = $objFP->fpCode($pwd, $key, $len); unset($objFP);
if ($code !== false) { echo $code; } else { echo ""; } } else { echo ""; }
class FlowerPassword { public function fpCode($password, $key, $length = 16) { if ($password && $key && (1 < $length) && ($length < 33)) { $hmd5 = hash_hmac('md5', $password, $key); $rule = str_split(hash_hmac('md5', $hmd5, "kise")); $source = str_split(hash_hmac('md5', $hmd5, "snow")); $str = "sunlovesnow1990090127xykab"; for ($i = 0; $i < 32; $i++) { if (!is_numeric($source[$i])) { if (stripos($str, $rule[$i]) !== false) { $source[$i] = strtoupper($source[$i]); } } } if (is_numeric($source[0])) { $source[0] = 'K'; } $code = substr(implode($source), 0, $length); return $code; } else { return false; } } }
?>
|