Skip to content

Commit

Permalink
#1 initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aleguerra05 committed May 26, 2024
0 parents commit fc1dc96
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package-lock.json
settings.json
node_modules
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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)
}

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
12 changes: 12 additions & 0 deletions settings.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"keys":[
{
"account":"Google Account",
"token":"AAAAAAAAAAAAAAAA"
},
{
"account":"GitHub Account",
"token":"BBBBBBBBBBBBBBBB"
}
]
}

0 comments on commit fc1dc96

Please sign in to comment.