Commit 2e1b7867 authored by Ahmad's avatar Ahmad

inikt

parent f232942d
// Import the required packages import clipboardy from 'clipboardy';
const otplib = require('otplib');
const clipboardy = require('clipboardy');
// Variable to store the last generated token
let lastToken = '';
// Function to check and display the 2FA code if it changes // Stores the previous clipboard content to detect changes
async function checkForNewCode() { let previousContent = "";
try {
// Read the secret key from the clipboard
const secret = await clipboardy.read();
// Generate the TOTP code using the secret from the clipboard // Function to check the clipboard content
const currentToken = otplib.authenticator.generate(secret); const checkClipboard = () => {
const currentContent = clipboardy.readSync();
// If the current token is different from the last token, log it // If the content has changed, display it
if (currentToken !== lastToken) { if (currentContent !== previousContent) {
console.log(`New 2FA code: ${currentToken}`); console.log("Clipboard Content:", currentContent);
lastToken = currentToken; previousContent = currentContent;
}
} catch (error) {
console.error("Failed to read from clipboard or generate TOTP:", error);
} }
} };
// Run the check every second (1000 ms) to monitor changes in the TOTP code // Check the clipboard every second
setInterval(checkForNewCode, 1000); setInterval(checkClipboard, 1000);
{ {
"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