Commit 2e1b7867 authored by Ahmad's avatar Ahmad

inikt

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