Skip to content

Instantly share code, notes, and snippets.

@t1m0thyj
Last active November 18, 2020 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t1m0thyj/24232d3c5c028db8bea1377fd2efd588 to your computer and use it in GitHub Desktop.
Save t1m0thyj/24232d3c5c028db8bea1377fd2efd588 to your computer and use it in GitHub Desktop.
const keytar = require("keytar");
const SERVICE = require("os").userInfo().username;
const ACCOUNT = "VeryLongValue";
async function testCred(length) {
const secret = '*'.repeat(length);
try {
await keytar.setPassword(SERVICE, ACCOUNT, secret);
} catch {
return false;
}
const newSecret = await keytar.getPassword(SERVICE, ACCOUNT);
return newSecret.length === secret.length;
}
async function findMaxLength() {
let length = 0;
while (length < 1e6) {
console.log(length);
length += 100;
const oldLength = length;
while (!(await testCred(length))) {
length--;
}
if (length !== oldLength) {
return length;
}
}
return length;
}
(async () => {
const maxLength = await findMaxLength();
console.log("Max credential length:", maxLength);
await keytar.deletePassword(SERVICE, ACCOUNT);
})().catch((error) => {
console.error(error);
process.exit(1);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment