Skip to content

Commit acd062c

Browse files
committed
Do not throw if hash.length != 60
1 parent d793f7e commit acd062c

File tree

5 files changed

+37
-41
lines changed

5 files changed

+37
-41
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
![bcrypt.js - bcrypt in plain JavaScript](https://raw.github.com/dcodeIO/bcrypt.js/master/bcrypt.png)
22
===========
33
Optimized bcrypt in plain JavaScript with zero dependencies. Compiled through Closure Compiler using advanced
4-
optimizations, 100% typed code. Fully compatible to [bcrypt](https://npmjs.org/package/bcrypt) and also working in the
5-
browser.
4+
optimizations, 100% typed code. Compatible to the C++ [bcrypt](https://npmjs.org/package/bcrypt) binding and also
5+
working in the browser.
66

77
Features ![Build Status](https://travis-ci.org/dcodeIO/bcrypt.js.png?branch=master)
88
--------

dist/bcrypt.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@
989989
*/
990990
bcrypt.hashSync = function(s, salt) {
991991
if (!salt) salt = GENSALT_DEFAULT_LOG2_ROUNDS;
992-
if (typeof salt == 'number') {
992+
if (typeof salt === 'number') {
993993
salt = bcrypt.genSaltSync(salt);
994994
}
995995
return _hash(s, salt);
@@ -1003,10 +1003,10 @@
10031003
* @expose
10041004
*/
10051005
bcrypt.hash = function(s, salt, callback) {
1006-
if (typeof callback != 'function') {
1006+
if (typeof callback !== 'function') {
10071007
throw(new Error("Illegal 'callback': "+callback));
10081008
}
1009-
if (typeof salt == 'number') {
1009+
if (typeof salt === 'number') {
10101010
bcrypt.genSalt(salt, function(err, salt) {
10111011
_hash(s, salt, callback);
10121012
});
@@ -1024,12 +1024,10 @@
10241024
* @expose
10251025
*/
10261026
bcrypt.compareSync = function(s, hash) {
1027-
if(typeof s != "string" || typeof hash != "string") {
1027+
if(typeof s !== "string" || typeof hash !== "string") {
10281028
throw(new Error("Illegal argument types: "+(typeof s)+', '+(typeof hash)));
10291029
}
1030-
if(hash.length != 60) {
1031-
throw(new Error("Illegal hash length: "+hash.length+" != 60"));
1032-
}
1030+
if (hash.length !== 60) return false;
10331031
var comp = bcrypt.hashSync(s, hash.substr(0, hash.length-31));
10341032
var same = comp.length == hash.length;
10351033
var max_length = (comp.length < hash.length) ? comp.length : hash.length;
@@ -1053,7 +1051,7 @@
10531051
* @expose
10541052
*/
10551053
bcrypt.compare = function(s, hash, callback) {
1056-
if (typeof callback != 'function') {
1054+
if (typeof callback !== 'function') {
10571055
throw(new Error("Illegal 'callback': "+callback));
10581056
}
10591057
bcrypt.hash(s, hash.substr(0, 29), function(err, comp) {
@@ -1069,7 +1067,7 @@
10691067
* @expose
10701068
*/
10711069
bcrypt.getRounds = function(hash) {
1072-
if(typeof hash != "string") {
1070+
if(typeof hash !== "string") {
10731071
throw(new Error("Illegal type of 'hash': "+(typeof hash)));
10741072
}
10751073
return parseInt(hash.split("$")[2], 10);
@@ -1083,19 +1081,19 @@
10831081
* @expose
10841082
*/
10851083
bcrypt.getSalt = function(hash) {
1086-
if (typeof hash != 'string') {
1084+
if (typeof hash !== 'string') {
10871085
throw(new Error("Illegal type of 'hash': "+(typeof hash)));
10881086
}
1089-
if(hash.length != 60) {
1087+
if (hash.length !== 60) {
10901088
throw(new Error("Illegal hash length: "+hash.length+" != 60"));
10911089
}
10921090
return hash.substring(0, 29);
10931091
};
10941092

10951093
// Enable module loading if available
1096-
if (typeof module != 'undefined' && module["exports"]) { // CommonJS
1094+
if (typeof module !== 'undefined' && module["exports"]) { // CommonJS
10971095
module["exports"] = bcrypt;
1098-
} else if (typeof define != 'undefined' && define["amd"]) { // AMD
1096+
} else if (typeof define !== 'undefined' && define["amd"]) { // AMD
10991097
define("bcrypt", function() { return bcrypt; });
11001098
} else { // Shim
11011099
if (!global["dcodeIO"]) {

dist/bcrypt.min.js

Lines changed: 12 additions & 12 deletions
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. 100% typed code. Fully compatible to 'bcrypt'.",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"author": "Daniel Wirtz <dcode@dcode.io>",
66
"contributors": [
77
"Shane Girish <shaneGirish@gmail.com> (https://github.com/shaneGirish)",

0 commit comments

Comments
 (0)