# unpc

> 🔒 Password hashing and verification library providing single interface for SHA256, SCrypt, BCrypt, Argon2 and PBKDF2 algorithms

Latest version **1.2.0** (published 2023-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install unpc
pnpm add unpc
yarn add unpc
bun add unpc
```

## Health

**Score 40/100 (D)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2023-02-19 |
| First published | 2022-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 408.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Alexander Gribochkin |
| Maintainers | alexxandergrib |
| Keywords | crypto, hashing, password, passwords, sha256, scrypt, bcrypt, argon2, pbkdf2, node, nodejs, typed, typescript, backend |

## Links

- npm: https://www.npmjs.com/package/unpc
- Repository: https://github.com/AlexXanderGrib/passwords-crypto
- Homepage: https://github.com/AlexXanderGrib/passwords-crypto#readme
- Issues: https://github.com/AlexXanderGrib/passwords-crypto/issues
- npm.io page: https://npm.io/package/unpc

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2023-02-19
- 1.1.2 — 2022-05-22
- 1.1.1 — 2022-05-12
- 1.1.0 — 2022-05-07
- 1.0.1 — 2022-05-07
- 1.0.0 — 2022-05-07

## README

# Universal NodeJS Passwords Crypto

> 🔒 Password hashing and verification library providing single interface for `SHA256`, `SCrypt`, `BCrypt`, `Argon2` and `PBKDF2` algorithms

[![Test Status](https://github.com/AlexXanderGrib/passwords-crypto/actions/workflows/test.yml/badge.svg)](https://github.com/AlexXanderGrib/passwords-crypto)
[![Downloads](https://img.shields.io/npm/dt/unpc.svg)](https://npmjs.com/package/unpc)
[![last commit](https://img.shields.io/github/last-commit/AlexXanderGrib/passwords-crypto.svg)](https://github.com/AlexXanderGrib/passwords-crypto)
[![codecov](https://img.shields.io/codecov/c/github/AlexXanderGrib/passwords-crypto/main.svg)](https://codecov.io/gh/AlexXanderGrib/passwords-crypto)
[![GitHub](https://img.shields.io/github/stars/AlexXanderGrib/passwords-crypto.svg)](https://github.com/AlexXanderGrib/passwords-crypto)
[![unpc](https://snyk.io/advisor/npm-package/unpc/badge.svg)](https://snyk.io/advisor/npm-package/unpc)
[![Known Vulnerabilities](https://snyk.io/test/npm/unpc/badge.svg)](https://snyk.io/test/npm/unpc)
[![Quality](https://img.shields.io/npms-io/quality-score/unpc.svg?label=quality%20%28npms.io%29&)](https://npms.io/search?q=unpc)
[![npm](https://img.shields.io/npm/v/unpc.svg)](https://npmjs.com/package/unpc)
[![license MIT](https://img.shields.io/npm/l/unpc.svg)](https://github.com/AlexXanderGrib/passwords-crypto/blob/main/LICENSE.txt)
[![Size](https://img.shields.io/bundlephobia/minzip/unpc)](https://bundlephobia.com/package/unpc)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/9f36664447bf472f95f1ee54b58b3f1f)](https://www.codacy.com/gh/AlexXanderGrib/passwords-crypto/dashboard?utm_source=github.com&utm_medium=referral&utm_content=AlexXanderGrib/passwords-crypto&utm_campaign=Badge_Grade)

## 🍬 Why use this lib?

- **Secure.** Library has only 2 dependencies and is constantly being scanned by Snyk & Code QL for vulnerabilities.
- **Simple.** Standardized api allows to do hashing, salting, peppering and verification with just 2 methods
- **Modular.** Every supported hashing algorithm is a simple class, that can be imported and used independently.

## 📦 Installation

- Using `npm`:
  ```bash
  npm i unpc
  ```
- Using `Yarn`:
  ```bash
  yarn add unpc
  ```
- Using `pnpm`:
  ```bash
  pnpm add unpc
  ```

### 🚚 Additional libraries

To support best hashing algorithms `unpc` needs third party libraries
with C bindings

#### Argon2

If you want to add support for [`argon2`](https://wikipedia.org/wiki/Argon2) algorithm
and `argon2i`, `argon2d` and `argon2id` adapters, you need to install package `argon2`

```bash
npm i argon2
```

#### BCrypt

If you want to add support for [`bcrypt`](https://wikipedia.org/wiki/Bcrypt) algorithm
and `bcrypt` adapter, you need to install package `bcrypt`

```bash
npm i bcrypt
```

## 🛠️ Examples

### Basic

```javascript
import { Crypt } from "unpc";
import { Argon2iHashingAdapter } from "unpc/argon2i";

const crypt = new Crypt({
  default: "argon2i",
  adapters: [Argon2iHashingAdapter],
  options: { encoding: "hex" }
});

const secret = "Hello world!";
const hash = await crypt.hash(secret);
console.log(hash);
//

const isCorrect = await crypt.verify(hash, secret);

console.log(isCorrect); // true
```

### Full examples

1. [Basic](./examples/1-base.mjs)
1. [With custom hashing adapter](./examples/2-custom.js)

## Adapters

| Path              | Adapter class name         | Algorithm | Requirements                               |
| ----------------- | -------------------------- | --------- | ------------------------------------------ |
| `unpc/argon2`     | `Argon2HashingAdapter`     | Argon2-i  | Package `argon2`                           |
| `unpc/argon2d`    | `Argon2dHashingAdapter`    | Argon2-d  | Package `argon2`                           |
| `unpc/argon2i`    | `Argon2iHashingAdapter`    | Argon2-i  | Package `argon2`                           |
| `unpc/argon2id`   | `Argon2idHashingAdapter`   | Argon2-id | Package `argon2`                           |
| `unpc/bcrypt`     | `BCryptHashingAdapter`     | Bcrypt    | Package `bcrypt`                           |
| `unpc/pbkdf2`     | `PBKDF2HashingAdapter`     | PBKDF2    | Node > `v0.5.5`                            |
| `unpc/scrypt`     | `SCryptHashingAdapter`     | Scrypt    | Node > `v10.5.0`                           |
| ~~`unpc/sha256`~~ | ~~`Sha256HashingAdapter`~~ | SHA-256   | Being brave enough to use it. **Insecure** |
| ~~`unpc/sha512`~~ | ~~`Sha512HashingAdapter`~~ | SHA-512   | Being brave enough to use it. **Insecure** |

## License

Distributed under the MIT License. See [LICENSE.txt](./LICENSE.txt) for more information.

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FAlexXanderGrib%2Fpasswords-crypto.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FAlexXanderGrib%2Fpasswords-crypto?ref=badge_large)

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