Commit 5975cbdd authored by Admin's avatar Admin

ddd

parent 9a564b05
......@@ -2,8 +2,11 @@
const { exec } = require("child_process");
const otplib = require("otplib");
// Expected length of the secret key
const expectedSecretLength = "ZGQ7DIXAENR5HPXONMYQJQPF2XVYM3OEUM4OBMBMDKRZ5DAVNYNPAISZTD76WML2".length;
// List of valid secret lengths
const validSecretLengths = [
"ZGQ7DIXAENR5HPXONMYQJQPF2XVYM3OEUM4OBMBMDKRZ5DAVNYNPAISZTD76WML2".length,
"QG5Z22ORKZC46SJRCCOPPEE5K475NHO7".length
];
// Store the last generated token and clipboard content
let lastToken = "";
......@@ -29,27 +32,29 @@ function checkForNewCode(secret) {
previousSecret = secret;
}
// Generate TOTP code using the current secret
const currentToken = otplib.authenticator.generate(secret);
try {
// Generate TOTP code using the current secret
const currentToken = otplib.authenticator.generate(secret);
// If the current token is different from the last token, log it
if (currentToken !== lastToken) {
console.log(`New 2FA code: ${currentToken}`);
lastToken = currentToken;
// If the current token is different from the last token, log it
if (currentToken !== lastToken) {
console.log(`New 2FA code: ${currentToken}`);
lastToken = currentToken;
}
} catch (error) {
console.error("Error generating TOTP code:", error.message);
}
}
// Run the clipboard read and TOTP generation every second, only on Windows
if (process.platform === "win32") {
setInterval(() => {
// Read the secret from clipboard and generate TOTP code if length matches
readClipboard((clipboardContent) => {
if (clipboardContent.length === expectedSecretLength) {
if (validSecretLengths.includes(clipboardContent.length)) {
checkForNewCode(clipboardContent);
} else {
checkForNewCode(previousSecret);
}
else
checkForNewCode(previousSecret)
});
}, 1000);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment