UNPKG

4.12 kBMarkdownView Raw
1bcrypt-nodejs
2===========================================
3
4Warning : A change was made in v0.0.3 to allow encoding of UTF-8 encoded strings. This causes strings encoded in v0.0.2 or earlier to not work in v0.0.3 anymore.
5
6Native JS implementation of BCrypt for Node.
7Has the same functionality as [node.bcrypt.js] expect for a few tiny differences.
8Mainly, it doesn't let you set the seed length for creating the random byte array.
9
10I created this version due to a small [problem](https://github.com/ncb000gt/node.bcrypt.js/issues/102) I faced with [node.bcrypt.js].
11Basically, to deploy one of my apps which uses [node.bcrypt.js] on a winx64 platform, I have to force the user to download about 1.6gb of sdks, buildtools and other requirements of which some fail to install ! Microsoft :(
12
13This code is based on [javascript-bcrypt] and uses [crypto] (http://nodejs.org/api/crypto.html) to create random byte arrays.
14
15Basic usage:
16-----------
17Synchronous
18```
19var hash = bcrypt.hashSync("bacon");
20
21bcrypt.compareSync("bacon", hash); // true
22bcrypt.compareSync("veggies", hash); // false
23```
24
25Asynchronous
26```
27bcrypt.hash("bacon", null, null, function(err, hash) {
28 // Store hash in your password DB.
29});
30
31// Load hash from your password DB.
32bcrypt.compare("bacon", hash, function(err, res) {
33 // res == true
34});
35bcrypt.compare("veggies", hash, function(err, res) {
36 // res = false
37});
38```
39
40In the above examples, the salt is automatically generated and attached to the hash.
41Though you can use your custom salt and there is no need for salts to be persisted as it will always be included in the final hash result and can be retrieved.
42
43API
44-------------------------
45* `genSaltSync(rounds)`
46 * `rounds` - [OPTIONAL] - the number of rounds to process the data for. (default - 10)
47* `genSalt(rounds, callback)`
48 * `rounds` - [OPTIONAL] - the number of rounds to process the data for. (default - 10)
49 * `callback` - [REQUIRED] - a callback to be fired once the salt has been generated.
50 * `error` - First parameter to the callback detailing any errors.
51 * `result` - Second parameter to the callback providing the generated salt.
52* `hashSync(data, salt)`
53 * `data` - [REQUIRED] - the data to be encrypted.
54 * `salt` - [REQUIRED] - the salt to be used in encryption.
55* `hash(data, salt, progress, cb)`
56 * `data` - [REQUIRED] - the data to be encrypted.
57 * `salt` - [REQUIRED] - the salt to be used to hash the password.
58 * `progress` - a callback to be called during the hash calculation to signify progress
59 * `callback` - [REQUIRED] - a callback to be fired once the data has been encrypted.
60 * `error` - First parameter to the callback detailing any errors.
61 * `result` - Second parameter to the callback providing the encrypted form.
62* `compareSync(data, encrypted)`
63 * `data` - [REQUIRED] - data to compare.
64 * `encrypted` - [REQUIRED] - data to be compared to.
65* `compare(data, encrypted, cb)`
66 * `data` - [REQUIRED] - data to compare.
67 * `encrypted` - [REQUIRED] - data to be compared to.
68 * `callback` - [REQUIRED] - a callback to be fired once the data has been compared.
69 * `error` - First parameter to the callback detailing any errors.
70 * `result` - Second parameter to the callback providing whether the data and encrypted forms match [true | false].
71* `getRounds(encrypted)` - return the number of rounds used to encrypt a given hash
72 * `encrypted` - [REQUIRED] - hash from which the number of rounds used should be extracted.
73
74Contributors
75============
76
77* [Alex Murray][alexmurray]
78* [Nicolas Pelletier][NicolasPelletier]
79* [Josh Rogers][geekymole]
80
81Credits
82-------------------------
83I heavily reused code from [javascript-bcrypt]. Though "Clipperz Javascript Crypto Library" was removed and its functionality replaced with "crypto".
84
85[node.bcrypt.js]:https://github.com/ncb000gt/node.bcrypt.js.git
86[javascript-bcrypt]:http://code.google.com/p/javascript-bcrypt/
87
88[alexmurray]:https://github.com/alexmurray
89[NicolasPelletier]:https://github.com/NicolasPelletier
90[geekymole]:https://github.com/geekymole
\No newline at end of file