diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..badf841 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +package-lock.json +settings.json +node_modules \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a2707e --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# TOTP Generator +This is a simple TOTP (Time-based One-Time Password) generator that generates TOTP codes for multiple accounts. + +## Usage +1. Create a settings.json file with your account tokens: + +```json +{ + "keys": [ + { + "account": "Email", + "token": "JBSWY3DPEHPK3PXP" + }, + { + "account": "GitHub", + "token": "JBSWY3DPEHPK3PXP" + } + ] +} +``` +1. Run node index.js + +It will generate and print the current TOTP codes for each account every 30 seconds. + +## Dependencies + +- totp-generator - Used to generate the TOTP codes +- fs - Used to read the settings file + +## License +MIT \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..2cff3cb --- /dev/null +++ b/index.js @@ -0,0 +1,41 @@ +import {TOTP} from 'totp-generator' +import { readFileSync } from 'fs' +import { exit } from 'process' + +let keys = [{ + account: 'UNDEFINED', + token: 'CCCCCCCCCCCCCCCC' +}] + +try { + const settings = readFileSync('./settings.json') + keys = JSON.parse(settings).keys +} catch (error) { + console.log('No settings file found (settings.json)') + exit(0) +} + +while (true) { + console.clear() + console.log('.........TOTP GENERATOR.........') + keys.forEach(element => { + GenerateOTP(element.account, element.token) + }) + + let nextIn = 0 + let secondsNow = new Date().getSeconds() + nextIn = secondsNow < 30 ? 30 - secondsNow : 60 - secondsNow + while (nextIn > 1) { + secondsNow = new Date().getSeconds() + nextIn = secondsNow < 30 ? 30 - secondsNow : 60 - secondsNow + process.stdout.write('\r'+new Date().toTimeString()+' Next in: '+nextIn+' seconds...') + await new Promise(resolve => setTimeout(resolve, 1000)) + } +} + +function GenerateOTP(account, token) { + const { otp } = TOTP.generate(token) + console.log(account) + console.log(otp) +} + diff --git a/package.json b/package.json new file mode 100644 index 0000000..53cea00 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "totp-generator", + "version": "1.0.0", + "description": "This is a simple TOTP (Time-based One-Time Password) generator that generates TOTP codes for multiple accounts.", + "main": "index.js", + "type": "module", + "scripts": { + "start": "node index.js", + "dev": "nodemon index.js" + }, + "author": "", + "license": "ISC", + "dependencies": { + "totp-generator": "^1.0.0" + }, + "devDependencies": { + "nodemon": "^3.1.1" + } +} diff --git a/settings.sample.json b/settings.sample.json new file mode 100644 index 0000000..86b5cbd --- /dev/null +++ b/settings.sample.json @@ -0,0 +1,12 @@ +{ + "keys":[ + { + "account":"Google Account", + "token":"AAAAAAAAAAAAAAAA" + }, + { + "account":"GitHub Account", + "token":"BBBBBBBBBBBBBBBB" + } + ] +} \ No newline at end of file