# node-tfa

> Two-factor authentication for nodejs

Latest version **1.0.13** (published 2024-07-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-tfa
pnpm add node-tfa
yarn add node-tfa
bun add node-tfa
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.13 |
| Published | 2024-07-12 |
| First published | 2020-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 20.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | t.kosminov |
| Maintainers | t.kosminov |
| Keywords | 2fa, tfa, authenticator |

## Links

- npm: https://www.npmjs.com/package/node-tfa
- Repository: https://github.com/tkosminov/node-2fa
- Homepage: https://github.com/tkosminov/node-2fa#readme
- Issues: https://github.com/tkosminov/node-2fa/issues
- npm.io page: https://npm.io/package/node-tfa

## Dependencies (3)

- [crypto](https://npm.io/package/crypto.md) ^1.0.1
- [nanoid](https://npm.io/package/nanoid.md) ^3.3.4
- [hi-base32](https://npm.io/package/hi-base32.md) ^0.5.1

## Recent versions

- 1.0.13 (latest) — 2024-07-12
- 1.0.11 — 2022-04-01
- 1.0.10 — 2021-10-20
- 1.0.9 — 2021-10-20
- 1.0.8 — 2021-10-20
- 1.0.7 — 2020-02-21
- 1.0.6 — 2020-02-21
- 1.0.5 — 2020-02-21
- 1.0.4 — 2020-02-21
- 1.0.3 — 2020-02-21
- 1.0.2 — 2020-02-21
- 1.0.1 — 2020-02-21
- 1.0.0 — 2020-02-21

## README

# node-tfa

<p align="center">
  <a href="https://www.npmjs.com/package/node-tfa" target="_blank"><img src="https://img.shields.io/npm/v/node-tfa.svg" alt="NPM Version"></a>
  <a href="https://www.npmjs.com/package/node-tfa" target="_blank"><img src="https://img.shields.io/npm/l/node-tfa.svg" alt="Package License"></a>
  <a href="https://www.npmjs.com/package/node-tfa" target="_blank"><img src="https://img.shields.io/npm/dm/node-tfa.svg" alt="NPM Downloads"></a>
</p>

## Installation

```bash
npm i node-tfa
```

## Usage

### Hotp

```ts
import Secret, { hotpGenerate, hotpVerify } from 'node-tfa';

const secret = new Secret({ label: 'USER_NAME', issuer: 'APP_NAME' })

const token = hotpGenerate({ secret: secret.base32, counter: 1 })

hotpVerify({ secret: secret.base32, counter: 1, token })
```

### Totp

```ts
import Secret, { totpGenerate, totpVerify } from 'node-tfa';

const secret = new Secret({ label: 'USER_NAME', issuer: 'APP_NAME' })

const token = totpGenerate({ secret: secret.base32 })

totpVerify({ secret: secret.base32, token })
```

### Google Authenticator

```ts
import Secret, { totpVerify } from 'node-tfa';

const secret = new Secret({ label: 'USER_NAME', issuer: 'APP_NAME', qr_code: true, type: 'totp' })

secret.qr_code

totpVerify({ secret: secret.base32, token: 'TOKEN_FROM_GOOGLE_AUTHENTICATOR' })
```

---
_Source: https://npm.io/package/node-tfa · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
