# node-tokenize

> A universal and secure token generator for authentication. Available in multiple languages, supports 2FA authentication flow.

Latest version **1.0.6** (published 2020-06-21) · BSD-3-Clause license · 0 weekly downloads

## Install

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

## 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.6 |
| Published | 2020-06-21 |
| First published | 2020-06-19 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 197.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Bowser65 |
| Maintainers | bowser65 |

## Links

- npm: https://www.npmjs.com/package/node-tokenize
- Repository: https://github.com/Bowser65/Tokenize
- Homepage: https://github.com/Bowser65/Tokenize#readme
- Issues: https://github.com/Bowser65/Tokenize/issues
- npm.io page: https://npm.io/package/node-tokenize

## Recent versions

- 1.0.6 (latest) — 2020-06-21
- 1.0.5 — 2020-06-21
- 1.0.3 — 2020-06-21
- 1.0.2 — 2020-06-21
- 1.0.1 — 2020-06-19
- 1.0.0 — 2020-06-19

## README

# Tokenize for Node.js
[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/G2G71TSDF)<br>
[![License](https://img.shields.io/github/license/Bowser65/Tokenize.svg?style=flat-square)](https://github.com/Bowser65/Tokenize/blob/master/LICENSE)

## Installation
```
With PNPM:
pnpm i node-tokenize

With Yarn:
yarn add node-tokenize

With NPM:
npm i node-tokenize
```

## How to use it
```js
import Tokenize from 'node-tokenize'
import Otp from 'node-tokenize/otp'

const tokenize = new Tokenize('Very strong and secure secret')

console.log(tokenize.generate('account_id')) // xxxxxxxx.xxxxxxxxxxx.xxxxxxxxx
console.log(tokenize.generate('account_id', 'prefix')) // prefix.xxxxxxxx.xxxxxxxxxxx.xxxxxxxxx

// Returns the account, or null if the token is invalid
console.log(tokenize.validate('xxxxxxxx.xxxxxxxxxxx.xxxxxxxxx', () => ({ tokensValidSince: 0 })))

// Get an OTP key
console.log(Otp.generateKey()) // You just need to save the base32 key in database

// Validate an OTP code
console.log(Otp.validateTotp("013370", "xxxxxxxxxxxxxxxx"))
console.log(Otp.validateHotp("013370", "xxxxxxxxxxxxxxxx", 1))
```

For specifications about how to use Tokenize in general, please refer to the top-level
[README](https://github.com/Bowser65/Tokenize/blob/master/README.md).

Looking to use this in a [Fastify](https://fastify.io) application? Give
[fastify-tokenize](https://github.com/Bowser65/fastify-tokenize) a look! :D

## TODO
 - Make it available to the web (through Web Crypto eventually)

## License
Like all official Tokenize implementation, this implementation is released under the BSD-3-Clause license.

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