# code-identifier

> stateless code identifier

Latest version **1.0.0** (published 2018-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install code-identifier
pnpm add code-identifier
yarn add code-identifier
bun add code-identifier
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-06-23 |
| First published | 2018-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 130.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tree Xie |
| Maintainers | tree.xie |

## Links

- npm: https://www.npmjs.com/package/code-identifier
- npm.io page: https://npm.io/package/code-identifier

## Dependencies (1)

- [keygrip](https://npm.io/package/keygrip.md) ^1.0.2

## Recent versions

- 1.0.0 (latest) — 2018-06-23

## README

# code-identifier

A stateless, valid verification code verification tool based on `keygrip`.

## API

### consturctor

- `opts.interval` time interval
- `opts.max` the max key count
- `opts.app` the name of application, for different app to generate code

```js
const CodeIdentifier = require('code-identifier');
const identifier = new CodeIdentifier({
  interval: 51 * 1000,
  max: 10,
  app: 'my-test-app',
});
```

### genCode

generate the code

- `len` the length of code
- `prefix` the prefix to generate code, such as `track cookie`, `user account` and so on. [optional]

```js
// { code: '512567', hash: 'flplYRZqe145QQJOlObmW8uNNY8' }
const result1 = identifier.genCode();

// { code: '53684948', hash: 'xixBFHNqGw6YdkPRLrTFR4NkyVI' }
const result2 = identifier.genCode(8);

// { code: '414337', hash: 'mTwUjHLhx_IGJ5FYbRT-np3b2ho' }
const result3 = identifier.genCode(6, 'track cookie');
```

### verify

verify the code

- `code` 
- `hash` the hash of genCode
- `prefix` the same as genCode use

```js
// true
const valid1 = identifier.verify('512567', 'flplYRZqe145QQJOlObmW8uNNY8');

// true
const valid2 = identifier.verify('414337', 'mTwUjHLhx_IGJ5FYbRT-np3b2ho', 'track cookie');
```

### getCode

Use custom function for get code

```js
identifier.getCode = (len) => crypto.randomBytes(len).toString('hex');

// { code: 'df19f3', hash: 'IfR9zTryXWkA_k93zF2hb0D0YHk' }
const result = identifier.genCode(3);
```

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