@types/bcrypt
- Version 5.0.2
- Published
- 9.86 kB
- 1 dependency
- MIT license
Install
npm i @types/bcrypt
yarn add @types/bcrypt
pnpm add @types/bcrypt
Overview
TypeScript definitions for bcrypt
Index
Functions
function compare
compare: { (data: string | Buffer, encrypted: string): Promise<boolean>; ( data: any, encrypted: string, callback: (err: Error, same: boolean) => any ): void;};
Parameter data
The data to be encrypted.
Parameter encrypted
The data to be compared against. A promise to be either resolved with the comparison result salt or rejected with an Error
Example 1
import * as bcrypt from 'bcrypt'; const myPlaintextPassword = 's0//\P4$$w0rD'; const someOtherPlaintextPassword = 'not_bacon';
(async () => { // Load hash from your password DB. const result1 = await bcrypt.compare(myPlaintextPassword, hash); // result1 == true
const result2 = await bcrypt.compare(someOtherPlaintextPassword, hash); // result2 == false })();
Parameter data
The data to be encrypted.
Parameter encrypted
The data to be compared against.
Parameter callback
A callback to be fire once the data has been compared. Uses eio making it asynchronous.
Example 1
import * as bcrypt from 'bcrypt'; const myPlaintextPassword = 's0//\P4$$w0rD'; const someOtherPlaintextPassword = 'not_bacon';
// Load hash from your password DB. bcrypt.compare(myPlaintextPassword, hash, (err, result) => { // result == true }); bcrypt.compare(someOtherPlaintextPassword, hash, (err, result) => { // result == false });
function compareSync
compareSync: (data: string | Buffer, encrypted: string) => boolean;
Parameter data
The data to be encrypted.
Parameter encrypted
The data to be compared against.
Example 1
import * as bcrypt from 'bcrypt'; const myPlaintextPassword = 's0//\P4$$w0rD'; const someOtherPlaintextPassword = 'not_bacon';
// Load hash from your password DB. bcrypt.compareSync(myPlaintextPassword, hash); // true bcrypt.compareSync(someOtherPlaintextPassword, hash); // false
function genSalt
genSalt: { (rounds?: number, minor?: 'a' | 'b'): Promise<string>; (callback: (err: Error, salt: string) => any): void; (rounds: number, callback: (err: Error, salt: string) => any): void; ( rounds: number, minor: 'a' | 'b', callback: (err: Error, salt: string) => any ): void;};
Parameter rounds
The cost of processing the data. Default 10.
Parameter minor
The minor version of bcrypt to use. Either 'a' or 'b'. Default 'b'. A promise to be either resolved with the generated salt or rejected with an Error
Example 1
import * as bcrypt from 'bcrypt'; const saltRounds = 10;
(async () => { const salt = await bcrypt.genSalt(saltRounds); })();
Parameter rounds
The cost of processing the data. Default 10.
Parameter minor
The minor version of bcrypt to use. Either 'a' or 'b'. Default 'b'.
Parameter callback
A callback to be fire once the salt has been generated. Uses eio making it asynchronous.
Example 1
import * as bcrypt from 'bcrypt'; const saltRounds = 10;
// Technique 1 (generate a salt and hash on separate function calls): bcrypt.genSalt(saltRounds, (err, salt) => { // ... });
function genSaltSync
genSaltSync: (rounds?: number, minor?: 'a' | 'b') => string;
Parameter rounds
The cost of processing the data. Default 10.
Parameter minor
The minor version of bcrypt to use. Either 'a' or 'b'. Default 'b'.
Example 1
import * as bcrypt from 'bcrypt'; const saltRounds = 10;
const salt = bcrypt.genSaltSync(saltRounds);
function getRounds
getRounds: (encrypted: string) => number;
Parameter encrypted
Hash from which the number of rounds used should be extracted.
Returns
The number of rounds used to encrypt a given hash.
function hash
hash: { (data: string | Buffer, saltOrRounds: string | number): Promise<string>; ( data: any, saltOrRounds: string | number, callback: (err: Error, encrypted: string) => any ): void;};
Parameter data
The data to be encrypted.
Parameter saltOrRounds
The salt to be used in encryption. If specified as a number then a salt will be generated with the specified number of rounds and used. A promise to be either resolved with the encrypted data salt or rejected with an Error
Example 1
import * as bcrypt from 'bcrypt'; const saltRounds = 10; const myPlaintextPassword = 's0//\P4$$w0rD';
(async () => { // Technique 1 (generate a salt and hash on separate function calls): const salt = await bcrypt.genSalt(saltRounds); const hash = await bcrypt.hash(myPlaintextPassword, salt); // Store hash in your password DB.
// Technique 2 (auto-gen a salt and hash): const hash2 = await bcrypt.hash(myPlaintextPassword, saltRounds); // Store hash in your password DB. })();
Parameter data
The data to be encrypted.
Parameter saltOrRounds
The salt to be used in encryption. If specified as a number then a salt will be generated with the specified number of rounds and used.
Parameter callback
A callback to be fired once the data has been encrypted. Uses eio making it asynchronous.
Example 1
import * as bcrypt from 'bcrypt'; const saltRounds = 10; const myPlaintextPassword = 's0//\P4$$w0rD';
// Technique 1 (generate a salt and hash on separate function calls): bcrypt.genSalt(saltRounds, (err, salt) => { bcrypt.hash(myPlaintextPassword, salt, (err, hash) => { // Store hash in your password DB. }); });
// Technique 2 (auto-gen a salt and hash): bcrypt.hash(myPlaintextPassword, saltRounds, (err, hash) => { // Store hash in your password DB. });
function hashSync
hashSync: (data: string | Buffer, saltOrRounds: string | number) => string;
Parameter data
The data to be encrypted.
Parameter saltOrRounds
The salt to be used to hash the password. If specified as a number then a salt will be generated with the specified number of rounds and used.
Example 1
import * as bcrypt from 'bcrypt'; const saltRounds = 10; const myPlaintextPassword = 's0//\P4$$w0rD';
// Technique 1 (generate a salt and hash on separate function calls): const salt = bcrypt.genSaltSync(saltRounds); const hash = bcrypt.hashSync(myPlaintextPassword, salt); // Store hash in your password DB.
// Technique 2 (auto-gen a salt and hash): const hash2 = bcrypt.hashSync(myPlaintextPassword, saltRounds); // Store hash in your password DB.
Package Files (1)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/bcrypt
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/bcrypt)
- HTML<a href="https://www.jsdocs.io/package/@types/bcrypt"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2305 ms. - Missing or incorrect documentation? Open an issue for this package.