对于大部分不重要网站,采用hash+salt的方式生成唯一密码,方便管理
在线工具
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| hashpw() { site="$1" [ -n "$site" ] || { echo "Usage: hashpw sitename"; return 1; }
seed="seed"
echo -n "Enter HMAC key: " read -s key echo
pw=$(printf '%s' "${seed}|${site}" \ | openssl dgst -sha256 -hmac "${key}" -binary \ | openssl base64 \ | tr -dc 'A-Za-z0-9' \ | cut -c1-12)
echo "$pw" }
|
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 57 58 59 60 61 62 63 64
| import * as crypto from "crypto"; import * as readline from "readline";
async function prompt(query: string, hidden = true): Promise<string> { return new Promise((resolve) => { const rl = readline.createInterface({ input: process.stdin, output: process.stdout, });
if (!hidden) { rl.question(query, (answer) => { rl.close(); resolve(answer); }); } else { process.stdout.write(query); const input: string[] = [];
const onData = (char: Buffer) => { const str = char.toString(); if (str === "\n" || str === "\r" || str === "\u0004") { process.stdin.removeListener("data", onData); rl.close(); process.stdout.write("\n"); resolve(input.join("")); } else { process.stdout.write("*"); input.push(str); } };
process.stdin.on("data", onData); } }); }
async function hashpw() { const site = process.argv[2]; if (!site) { console.log("Usage: ts-node hashpw.ts sitename"); return; }
const seed = "seed"; const key = await prompt("Enter HMAC key: ", true);
const hmac = crypto.createHmac("sha256", key); hmac.update(`${seed}|${site}`); const digest = hmac.digest("base64");
const pw = digest.replace(/[^A-Za-z0-9]/g, "").slice(0, 12);
console.log(pw); }
hashpw();
|