Skip to content

Commit 40e7a16

Browse files
committed
use strict, support $2y$ hashes
1 parent 14c98f8 commit 40e7a16

5 files changed

Lines changed: 13 additions & 8 deletions

File tree

dist/bcrypt.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* see: https://github.com/dcodeIO/bcrypt.js for details
3333
*/
3434
(function(global) {
35+
"use strict";
3536

3637
/**
3738
* @type {Array.<string>}
@@ -839,7 +840,7 @@
839840
offset = 3;
840841
} else {
841842
minor = salt.charAt(2);
842-
if (minor != 'a' || salt.charAt(3) != '$') {
843+
if ((minor !== 'a' && minor !== 'y') || salt.charAt(3) !== '$') {
843844
err = new Error("Invalid salt revision: "+salt.substring(2,4));
844845
if (callback) {
845846
_nextTick(callback.bind(this, err));
@@ -861,7 +862,7 @@
861862
var r2 = parseInt(salt.substring(offset + 1, offset + 2), 10);
862863
var rounds = r1 + r2;
863864
var real_salt = salt.substring(offset + 3, offset + 25);
864-
s += minor >= 'a' ? "\000" : "";
865+
s += minor >= 'a' ? "\x00" : "";
865866

866867
var passwordb = _stringToBytes(s);
867868
var saltb = [];

dist/bcrypt.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bcryptjs",
33
"description": "Optimized bcrypt in plain JavaScript with zero dependencies. Compatible to 'bcrypt'.",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"author": "Daniel Wirtz <dcode@dcode.io>",
66
"contributors": [
77
"Shane Girish <shaneGirish@gmail.com> (https://github.com/shaneGirish)",

src/bcrypt.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* see: https://github.com/dcodeIO/bcrypt.js for details
3333
*/
3434
(function(global) {
35+
"use strict";
3536

3637
// #include "base64/native.js"
3738

@@ -592,7 +593,7 @@
592593
offset = 3;
593594
} else {
594595
minor = salt.charAt(2);
595-
if (minor != 'a' || salt.charAt(3) != '$') {
596+
if ((minor !== 'a' && minor !== 'y') || salt.charAt(3) !== '$') {
596597
err = new Error("Invalid salt revision: "+salt.substring(2,4));
597598
if (callback) {
598599
_nextTick(callback.bind(this, err));
@@ -614,7 +615,7 @@
614615
var r2 = parseInt(salt.substring(offset + 1, offset + 2), 10);
615616
var rounds = r1 + r2;
616617
var real_salt = salt.substring(offset + 3, offset + 25);
617-
s += minor >= 'a' ? "\000" : "";
618+
s += minor >= 'a' ? "\x00" : "";
618619

619620
var passwordb = _stringToBytes(s);
620621
var saltb = [];

tests/suite.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ module.exports = {
4949
},
5050

5151
"compare": function(test) {
52-
var hash1 = bcrypt.hashSync("hello", bcrypt.genSaltSync());
53-
var hash2 = bcrypt.hashSync("world", bcrypt.genSaltSync());
52+
var salt1 = bcrypt.genSaltSync(),
53+
hash1 = bcrypt.hashSync("hello", salt1); // $2a$
54+
var salt2 = bcrypt.genSaltSync();
55+
salt2 = salt2.substring(0,2)+'y'+salt2.substring(3); // $2y$
56+
var hash2 = bcrypt.hashSync("world", salt2);
5457
bcrypt.compare("hello", hash1, function(err, same) {
5558
test.notOk(err);
5659
test.ok(same);

0 commit comments

Comments
 (0)