Commit 5da0866c authored by Ahmad's avatar Ahmad

inikt

parent 2e1b7867
import clipboardy from 'clipboardy'; // Import required packages
const { exec } = require("child_process");
const otplib = require("otplib");
// Store the last generated token and clipboard content
let lastToken = "";
let previousSecret = "";
// Stores the previous clipboard content to detect changes // Function to read the clipboard content on Windows
let previousContent = ""; function readClipboard(callback) {
exec("powershell Get-Clipboard", (error, stdout) => {
if (error) {
console.error("Error reading clipboard:", error);
return;
}
// Function to check the clipboard content // Pass the clipboard content to the callback function
const checkClipboard = () => { callback(stdout.trim());
const currentContent = clipboardy.readSync(); });
}
// If the content has changed, display it // Function to generate and display the TOTP code if the secret changes
if (currentContent !== previousContent) { function checkForNewCode(secret) {
console.log("Clipboard Content:", currentContent); if (secret !== previousSecret) {
previousContent = currentContent; console.log(`Detected new secret key from clipboard: ${secret}`);
previousSecret = secret;
} }
};
// Check the clipboard every second // Generate TOTP code using the current secret
setInterval(checkClipboard, 1000); 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;
}
}
// 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
readClipboard((secret) => {
if (secret) {
checkForNewCode(secret);
}
});
}, 1000);
} else {
console.log("This script only runs on Windows.");
}
{ {
"name": "aws", "name": "aws",
"version": "1.0.0", "version": "1.0.0",
"type": "module",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
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