|
1 | | - |
| 1 | + |
2 | 2 | =========== |
3 | | -Optimized bcrypt in plain JavaScript with zero dependencies. Compatible to the C++ [bcrypt](https://npmjs.org/package/bcrypt) |
4 | | -binding and also working in the browser. |
5 | | - |
6 | | -Features  |
7 | | --------- |
8 | | -* CommonJS compatible (via [crypto](http://nodejs.org/api/crypto.html)), also available via [npm](https://npmjs.org/package/bcryptjs) |
9 | | -* Browser compatible (via [WebCryptoAPI](http://www.w3.org/TR/WebCryptoAPI)) |
10 | | -* AMD compatible |
11 | | -* Zero production dependencies |
12 | | -* Small footprint |
13 | | -* ISAAC PRNG as default fallback with bcrypt-isaac.js |
14 | | -* Compiled with Closure Compiler using advanced optimizations, [externs included](https://github.com/dcodeIO/bcrypt.js/blob/master/externs/bcrypt.js) |
| 3 | +Optimized bcrypt in JavaScript with zero dependencies. Compatible to the C++ [bcrypt](https://npmjs.org/package/bcrypt) |
| 4 | +binding on node.js and also working in the browser. |
| 5 | + |
| 6 | +[](https://travis-ci.org/dcodeIO/bcrypt.js) |
| 7 | +[](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=info%40code-emitter.com&item_name=Open%20Source%3A%20bcrypt.js) |
15 | 8 |
|
16 | 9 | Security considerations |
17 | 10 | ----------------------- |
18 | 11 | Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function: over time, the |
19 | 12 | iteration count can be increased to make it slower, so it remains resistant to brute-force search attacks even with |
20 | 13 | increasing computation power. ([see](http://en.wikipedia.org/wiki/Bcrypt)) |
21 | 14 |
|
22 | | -While bcrypt.js is compatible to the C++ bcrypt binding, it is written in pure JavaScript and thus slower, effectively |
23 | | -reducing the number of iterations that can be processed in an equal time span. |
| 15 | +While bcrypt.js is compatible to the C++ bcrypt binding, it is written in pure JavaScript and thus slower ([about 2.7 |
| 16 | +times](https://github.com/dcodeIO/bcrypt.js/wiki/Benchmark)), effectively reducing the number of iterations that can be |
| 17 | +processed in an equal time span. |
24 | 18 |
|
25 | 19 | Usage |
26 | 20 | ----- |
| 21 | +The library is compatible with CommonJS and AMD loaders and is exposed globally as `dcodeIO.bcrypt` if neither is |
| 22 | +available. |
| 23 | + |
| 24 | +### node.js |
| 25 | + |
| 26 | +On node.js, the inbuilt [crypto module](http://nodejs.org/api/crypto.html)'s randomBytes interface is used to obtain |
| 27 | +secure random numbers. |
27 | 28 |
|
28 | | -#### node.js |
29 | 29 | `npm install bcryptjs` |
30 | 30 |
|
31 | | -```javascript |
| 31 | +```js |
32 | 32 | var bcrypt = require('bcryptjs'); |
33 | 33 | ... |
34 | 34 | ``` |
35 | 35 |
|
36 | | -#### RequireJS/AMD |
37 | | -```javascript |
| 36 | +### Browser |
| 37 | + |
| 38 | +In the browser, bcrypt.js by default relies on [Web Crypto API](http://www.w3.org/TR/WebCryptoAPI)'s getRandomValues |
| 39 | +interface to obtain secure random numbers. bcrypt-isaac.js additionally ships with the ISAACs PRNG used as the default |
| 40 | +fallback if the former is not available. See [bcrypt.setRandomFallback](https://github.com/dcodeIO/bcrypt.js#setrandomfallbackrandom) |
| 41 | +to set a custom fallback. |
| 42 | + |
| 43 | +```js |
| 44 | +var bcrypt = dcodeIO.bcrypt; |
| 45 | +... |
| 46 | +``` |
| 47 | + |
| 48 | +or |
| 49 | + |
| 50 | +```js |
38 | 51 | require.config({ |
39 | | - "paths": { |
40 | | - "bcrypt": "/path/to/bcrypt.js" |
41 | | - } |
| 52 | + paths: { "bcrypt": "/path/to/bcrypt.js" } |
42 | 53 | }); |
43 | 54 | require(["bcrypt"], function(bcrypt) { |
44 | 55 | ... |
45 | 56 | }); |
46 | 57 | ``` |
47 | 58 |
|
48 | | -#### Shim/browser |
49 | | -```html |
50 | | -<script src="//raw.github.com/dcodeIO/bcrypt.js/master/bcrypt.min.js"></script> |
51 | | -``` |
52 | | -```javascript |
53 | | -var bcrypt = dcodeIO.bcrypt; |
54 | | -... |
55 | | -``` |
56 | | - |
57 | 59 | Usage - Sync |
58 | 60 | ------------ |
59 | 61 | To hash a password: |
@@ -229,4 +231,4 @@ which is itself based on [javascript-bcrypt](http://code.google.com/p/javascript |
229 | 231 |
|
230 | 232 | License |
231 | 233 | ------- |
232 | | -Apache License, Version 2.0 if not stated otherwise |
| 234 | +New-BSD / MIT ([see](https://github.com/dcodeIO/bcrypt.js/blob/master/LICENSE)) |
0 commit comments