{"name":"bcryptjs","version":"3.0.3","keywords":["bcrypt","password","auth","authentication","encryption","crypt","crypto"],"author":{"name":"Daniel Wirtz","email":"dcode@dcode.io"},"license":"BSD-3-Clause","_id":"bcryptjs@3.0.3","maintainers":[{"name":"dcode","email":"dcode+npm@dcode.io"}],"contributors":[{"url":"https://github.com/shaneGirish","name":"Shane Girish","email":"shaneGirish@gmail.com"},{"url":"https://github.com/alexmurray","name":"Alex Murray"},{"url":"https://github.com/NicolasPelletier","name":"Nicolas Pelletier"},{"url":"https://github.com/geekymole","name":"Josh Rogers"},{"url":"https://github.com/nisaacson","name":"Noah Isaacson","email":"noah@nisaacson.com"}],"homepage":"https://github.com/dcodeIO/bcrypt.js#readme","bugs":{"url":"https://github.com/dcodeIO/bcrypt.js/issues"},"bin":{"bcrypt":"bin/bcrypt"},"dist":{"shasum":"4b93d6a398c48bfc9f32ee65d301174a8a8ea56f","tarball":"http://registry-npm.ywwl.com/bcryptjs/download/bcryptjs-3.0.3.tgz","fileCount":11,"integrity":"sha512-GlF5wPWnSa/X5LKM1o0wz0suXIINz1iHRLvTS+sLyi7XPbe5ycmYI3DlZqVGZZtDgl4DmasFg7gOB3JYbphV5g==","signatures":[{"sig":"MEQCIFHegryuJgdifssRES4vYL42bVukzAdIJE9K2mprrHmMAiBeviGM1aSAbsA/tfFCfxQ2rbiULXR9bVHqaMUO2+tQGg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":112292,"size":32384,"noattachment":false,"key":"/bcryptjs/-/bcryptjs-3.0.3.tgz"},"main":"umd/index.js","type":"module","types":"umd/index.d.ts","browser":{"crypto":false},"exports":{".":{"import":{"types":"./index.d.ts","default":"./index.js"},"require":{"types":"./umd/index.d.ts","default":"./umd/index.js"}}},"gitHead":"1211e9a2213e0b3ee232a204b3ce899beebce31a","scripts":{"lint":"prettier --check .","test":"npm run test:unit && npm run test:typescript","build":"node scripts/build.js","format":"prettier --write .","test:unit":"node tests","test:typescript":"tsc --project tests/typescript/tsconfig.esnext.json && tsc --project tests/typescript/tsconfig.nodenext.json && tsc --project tests/typescript/tsconfig.commonjs.json && tsc --project tests/typescript/tsconfig.global.json"},"_npmUser":{"name":"dcode","email":"dcode+npm@dcode.io"},"repository":{"url":"git+https://github.com/dcodeIO/bcrypt.js.git","type":"url"},"_npmVersion":"11.6.2","description":"Optimized bcrypt in plain JavaScript with zero dependencies, with TypeScript support. Compatible to 'bcrypt'.","directories":{},"_nodeVersion":"25.1.0","_hasShrinkwrap":false,"devDependencies":{"bcrypt":"^5.1.1","esm2umd":"^0.3.1","prettier":"^3.5.0","typescript":"^5.7.3"},"_npmOperationalInternal":{"tmp":"tmp/bcryptjs_3.0.3_1762121383238_0.2189625587599564","host":"s3://npm-registry-packages-npm-production"},"readme":"# bcrypt.js\n\nOptimized bcrypt in JavaScript with zero dependencies, with TypeScript support. Compatible to the C++\n[bcrypt](https://npmjs.org/package/bcrypt) binding on Node.js and also working in the browser.\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/dcodeIO/bcrypt.js/test.yml?branch=main&label=test&logo=github)](https://github.com/dcodeIO/bcrypt.js/actions/workflows/test.yml) [![Publish Status](https://img.shields.io/github/actions/workflow/status/dcodeIO/bcrypt.js/publish.yml?branch=main&label=publish&logo=github)](https://github.com/dcodeIO/bcrypt.js/actions/workflows/publish.yml) [![npm](https://img.shields.io/npm/v/bcryptjs.svg?label=npm&color=007acc&logo=npm)](https://www.npmjs.com/package/bcryptjs)\n\n## Security considerations\n\nBesides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function: over time, the\niteration count can be increased to make it slower, so it remains resistant to brute-force search attacks even with\nincreasing computation power. ([see](http://en.wikipedia.org/wiki/Bcrypt))\n\nWhile bcrypt.js is compatible to the C++ bcrypt binding, it is written in pure JavaScript and thus slower ([about 30%](https://github.com/dcodeIO/bcrypt.js/wiki/Benchmark)), effectively reducing the number of iterations that can be\nprocessed in an equal time span.\n\nThe maximum input length is 72 bytes (note that UTF-8 encoded characters use up to 4 bytes) and the length of generated\nhashes is 60 characters. Note that maximum input length is not implicitly checked by the library for compatibility with\nthe C++ binding on Node.js, but should be checked with `bcrypt.truncates(password)` where necessary.\n\n## Usage\n\nThe package exports an ECMAScript module with an UMD fallback.\n\n```\n$> npm install bcryptjs\n```\n\n```ts\nimport bcrypt from \"bcryptjs\";\n```\n\n### Usage with a CDN\n\n- From GitHub via [jsDelivr](https://www.jsdelivr.com):<br />\n  `https://cdn.jsdelivr.net/gh/dcodeIO/bcrypt.js@TAG/index.js` (ESM)\n- From npm via [jsDelivr](https://www.jsdelivr.com):<br />\n  `https://cdn.jsdelivr.net/npm/bcryptjs@VERSION/index.js` (ESM)<br />\n  `https://cdn.jsdelivr.net/npm/bcryptjs@VERSION/umd/index.js` (UMD)\n- From npm via [unpkg](https://unpkg.com):<br />\n  `https://unpkg.com/bcryptjs@VERSION/index.js` (ESM)<br />\n  `https://unpkg.com/bcryptjs@VERSION/umd/index.js` (UMD)\n\nReplace `TAG` respectively `VERSION` with a [specific version](https://github.com/dcodeIO/bcrypt.js/releases) or omit it (not recommended in production) to use latest.\n\nWhen using the ESM variant in a browser, the `crypto` import needs to be stubbed out, for example using an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap). Bundlers should omit it automatically.\n\n### Usage - Sync\n\nTo hash a password:\n\n```ts\nconst salt = bcrypt.genSaltSync(10);\nconst hash = bcrypt.hashSync(\"B4c0/\\/\", salt);\n// Store hash in your password DB\n```\n\nTo check a password:\n\n```ts\n// Load hash from your password DB\nbcrypt.compareSync(\"B4c0/\\/\", hash); // true\nbcrypt.compareSync(\"not_bacon\", hash); // false\n```\n\nAuto-gen a salt and hash:\n\n```ts\nconst hash = bcrypt.hashSync(\"bacon\", 10);\n```\n\n### Usage - Async\n\nTo hash a password:\n\n```ts\nconst salt = await bcrypt.genSalt(10);\nconst hash = await bcrypt.hash(\"B4c0/\\/\", salt);\n// Store hash in your password DB\n```\n\n```ts\nbcrypt.genSalt(10, (err, salt) => {\n  bcrypt.hash(\"B4c0/\\/\", salt, function (err, hash) {\n    // Store hash in your password DB\n  });\n});\n```\n\nTo check a password:\n\n```ts\n// Load hash from your password DB\nawait bcrypt.compare(\"B4c0/\\/\", hash); // true\nawait bcrypt.compare(\"not_bacon\", hash); // false\n```\n\n```ts\n// Load hash from your password DB\nbcrypt.compare(\"B4c0/\\/\", hash, (err, res) => {\n  // res === true\n});\nbcrypt.compare(\"not_bacon\", hash, (err, res) => {\n  // res === false\n});\n```\n\nAuto-gen a salt and hash:\n\n```ts\nawait bcrypt.hash(\"B4c0/\\/\", 10);\n// Store hash in your password DB\n```\n\n```ts\nbcrypt.hash(\"B4c0/\\/\", 10, (err, hash) => {\n  // Store hash in your password DB\n});\n```\n\n**Note:** Under the hood, asynchronous APIs split an operation into small chunks. After the completion of a chunk, the execution of the next chunk is placed on the back of the [JS event queue](https://developer.mozilla.org/en/docs/Web/JavaScript/EventLoop), efficiently yielding for other computation to execute.\n\n### Usage - Command Line\n\n```\nUsage: bcrypt <input> [rounds|salt]\n```\n\n## API\n\n### Callback types\n\n- **Callback<`T`>**: `(err: Error | null, result?: T) => void`<br />\n  Called with an error on failure or a value of type `T` upon success.\n\n- **ProgressCallback**: `(percentage: number) => void`<br />\n  Called with the percentage of rounds completed (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms.\n\n- **RandomFallback**: `(length: number) => number[]`<br />\n  Called to obtain random bytes when both [Web Crypto API](http://www.w3.org/TR/WebCryptoAPI/) and Node.js\n  [crypto](http://nodejs.org/api/crypto.html) are not available.\n\n### Functions\n\n- bcrypt.**genSaltSync**(rounds?: `number`): `string`<br />\n  Synchronously generates a salt. Number of rounds defaults to 10 when omitted.\n\n- bcrypt.**genSalt**(rounds?: `number`): `Promise<string>`<br />\n  Asynchronously generates a salt. Number of rounds defaults to 10 when omitted.\n\n- bcrypt.**genSalt**([rounds: `number`, ]callback: `Callback<string>`): `void`<br />\n  Asynchronously generates a salt. Number of rounds defaults to 10 when omitted.\n\n- bcrypt.**truncates**(password: `string`): `boolean`<br />\n  Tests if a password will be truncated when hashed, that is its length is greater than 72 bytes when converted to UTF-8.\n\n- bcrypt.**hashSync**(password: `string`, salt?: `number | string`): `string`\n  Synchronously generates a hash for the given password. Number of rounds defaults to 10 when omitted.\n\n- bcrypt.**hash**(password: `string`, salt: `number | string`): `Promise<string>`<br />\n  Asynchronously generates a hash for the given password.\n\n- bcrypt.**hash**(password: `string`, salt: `number | string`, callback: `Callback<string>`, progressCallback?: `ProgressCallback`): `void`<br />\n  Asynchronously generates a hash for the given password.\n\n- bcrypt.**compareSync**(password: `string`, hash: `string`): `boolean`<br />\n  Synchronously tests a password against a hash.\n\n- bcrypt.**compare**(password: `string`, hash: `string`): `Promise<boolean>`<br />\n  Asynchronously compares a password against a hash.\n\n- bcrypt.**compare**(password: `string`, hash: `string`, callback: `Callback<boolean>`, progressCallback?: `ProgressCallback`)<br />\n  Asynchronously compares a password against a hash.\n\n- bcrypt.**getRounds**(hash: `string`): `number`<br />\n  Gets the number of rounds used to encrypt the specified hash.\n\n- bcrypt.**getSalt**(hash: `string`): `string`<br />\n  Gets the salt portion from a hash. Does not validate the hash.\n\n- bcrypt.**setRandomFallback**(random: `RandomFallback`): `void`<br />\n  Sets the pseudo random number generator to use as a fallback if neither [Web Crypto API](http://www.w3.org/TR/WebCryptoAPI/) nor Node.js [crypto](http://nodejs.org/api/crypto.html) are available. Please note: It is highly important that the PRNG used is cryptographically secure and that it is seeded properly!\n\n## Building\n\nBuilding the UMD fallback:\n\n```\n$> npm run build\n```\n\nRunning the [tests](./tests):\n\n```\n$> npm test\n```\n\n## Credits\n\nBased on work started by Shane Girish at [bcrypt-nodejs](https://github.com/shaneGirish/bcrypt-nodejs), which is itself\nbased on [javascript-bcrypt](http://code.google.com/p/javascript-bcrypt/) (New BSD-licensed).\n","publish_time":1762121383466,"_cnpm_publish_time":1762121383466,"dist-tags":{"latest":"3.0.3"}}