# @mongez/password

> A password hash generator and verifier for Nodejs.

Latest version **1.0.2** (published 2022-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mongez/password
pnpm add @mongez/password
yarn add @mongez/password
bun add @mongez/password
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-11-14 |
| First published | 2022-11-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | hassanzohdy |
| Maintainers | hassanzohdy |
| Keywords | password, hash, make, generate, verify, brute-force |

## Links

- npm: https://www.npmjs.com/package/@mongez/password
- Repository: https://github.com/hassanzohdy/mongez-password
- npm.io page: https://npm.io/package/@mongez/password

## Dependencies (1)

- [bcryptjs](https://npm.io/package/bcryptjs.md) ^2.4.3

## 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.0.2 (latest) — 2022-11-14
- 1.0.1 — 2022-11-07
- 1.0.0 — 2022-11-07

## README

# Mongez Password

A Simple Password Hash Generator and Verifier for Node Js

> This package is a wrapper over [bcryptjs](https://www.npmjs.com/package/bcryptjs) as it is being used to generate and verify passwords.

## Installation

`yarn add @mongez/password`

Or

`npm i @mongez/password`

## Generating Password Hash

To generate a password hash, just import the Package and call the `generate` method.

```ts
import Password from '@mongez/password';

// generate a password hash
const hash = await Password.generate('123456');

console.log(hash); // $2a$15$Yw76mQjsULdRb14qtBZ7Y.iMkJNrbewQ4cpX/PPP0nt4wQuUo70Fu
```

Alternatively, you can use the `hash` method.

```ts
import { hash } from '@mongez/password';

// generate a password hash
const hash = hash('123456');

console.log(hash); // $2a$15$Yw76mQjsULdRb14qtBZ7Y.iMkJNrbewQ4cpX/PPP0nt4wQuUo70Fu
```

## Verifying Password

To verify a password, just import the Package and call the `verify` method.

```ts
import Password from '@mongez/password';

// verify a password
const isValid = await Password.verify('123456', '$2a$15$Yw76mQjsULdRb14qtBZ7Y.iMkJNrbewQ4cpX/PPP0nt4wQuUo70Fu'); // true
```

Or you can import directly the `verify` method.

```ts
import { verify } from '@mongez/password';

// verify a password
const isValid = verify('123456', '$2a$15$Yw76mQjsULdRb14qtBZ7Y.iMkJNrbewQ4cpX/PPP0nt4wQuUo70Fu'); // true
```

## Custom Salt

By default the generated password has value of salt equals to `15` but you can change it by passing the `salt` option.

```ts
import Password from '@mongez/password';

// generate a password hash
const hash = await Password.generate('123456', 10);

console.log(hash); // $2a$10$Yw76mQjsULdRb14qtBZ7Y.iMkJNrbewQ4cpX/PPP0nt4wQuUo70Fu
```

Or you can change the default salt value directly using `setDefaultPasswordSalt` method.

```ts
import Password, { setDefaultPasswordSalt } from '@mongez/password';

// set default salt
setDefaultPasswordSalt(10);

// generate a password hash
const hash = await Password.generate('123456'); // will be generated with salt equals to 10
```

## Tests

To run the tests, just run the following command:

`yarn test`

## License

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

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