|
989 | 989 | */ |
990 | 990 | bcrypt.hashSync = function(s, salt) { |
991 | 991 | if (!salt) salt = GENSALT_DEFAULT_LOG2_ROUNDS; |
992 | | - if (typeof salt == 'number') { |
| 992 | + if (typeof salt === 'number') { |
993 | 993 | salt = bcrypt.genSaltSync(salt); |
994 | 994 | } |
995 | 995 | return _hash(s, salt); |
|
1003 | 1003 | * @expose |
1004 | 1004 | */ |
1005 | 1005 | bcrypt.hash = function(s, salt, callback) { |
1006 | | - if (typeof callback != 'function') { |
| 1006 | + if (typeof callback !== 'function') { |
1007 | 1007 | throw(new Error("Illegal 'callback': "+callback)); |
1008 | 1008 | } |
1009 | | - if (typeof salt == 'number') { |
| 1009 | + if (typeof salt === 'number') { |
1010 | 1010 | bcrypt.genSalt(salt, function(err, salt) { |
1011 | 1011 | _hash(s, salt, callback); |
1012 | 1012 | }); |
|
1024 | 1024 | * @expose |
1025 | 1025 | */ |
1026 | 1026 | bcrypt.compareSync = function(s, hash) { |
1027 | | - if(typeof s != "string" || typeof hash != "string") { |
| 1027 | + if(typeof s !== "string" || typeof hash !== "string") { |
1028 | 1028 | throw(new Error("Illegal argument types: "+(typeof s)+', '+(typeof hash))); |
1029 | 1029 | } |
1030 | | - if(hash.length != 60) { |
1031 | | - throw(new Error("Illegal hash length: "+hash.length+" != 60")); |
1032 | | - } |
| 1030 | + if (hash.length !== 60) return false; |
1033 | 1031 | var comp = bcrypt.hashSync(s, hash.substr(0, hash.length-31)); |
1034 | 1032 | var same = comp.length == hash.length; |
1035 | 1033 | var max_length = (comp.length < hash.length) ? comp.length : hash.length; |
|
1053 | 1051 | * @expose |
1054 | 1052 | */ |
1055 | 1053 | bcrypt.compare = function(s, hash, callback) { |
1056 | | - if (typeof callback != 'function') { |
| 1054 | + if (typeof callback !== 'function') { |
1057 | 1055 | throw(new Error("Illegal 'callback': "+callback)); |
1058 | 1056 | } |
1059 | 1057 | bcrypt.hash(s, hash.substr(0, 29), function(err, comp) { |
|
1069 | 1067 | * @expose |
1070 | 1068 | */ |
1071 | 1069 | bcrypt.getRounds = function(hash) { |
1072 | | - if(typeof hash != "string") { |
| 1070 | + if(typeof hash !== "string") { |
1073 | 1071 | throw(new Error("Illegal type of 'hash': "+(typeof hash))); |
1074 | 1072 | } |
1075 | 1073 | return parseInt(hash.split("$")[2], 10); |
|
1083 | 1081 | * @expose |
1084 | 1082 | */ |
1085 | 1083 | bcrypt.getSalt = function(hash) { |
1086 | | - if (typeof hash != 'string') { |
| 1084 | + if (typeof hash !== 'string') { |
1087 | 1085 | throw(new Error("Illegal type of 'hash': "+(typeof hash))); |
1088 | 1086 | } |
1089 | | - if(hash.length != 60) { |
| 1087 | + if (hash.length !== 60) { |
1090 | 1088 | throw(new Error("Illegal hash length: "+hash.length+" != 60")); |
1091 | 1089 | } |
1092 | 1090 | return hash.substring(0, 29); |
1093 | 1091 | }; |
1094 | 1092 |
|
1095 | 1093 | // Enable module loading if available |
1096 | | - if (typeof module != 'undefined' && module["exports"]) { // CommonJS |
| 1094 | + if (typeof module !== 'undefined' && module["exports"]) { // CommonJS |
1097 | 1095 | module["exports"] = bcrypt; |
1098 | | - } else if (typeof define != 'undefined' && define["amd"]) { // AMD |
| 1096 | + } else if (typeof define !== 'undefined' && define["amd"]) { // AMD |
1099 | 1097 | define("bcrypt", function() { return bcrypt; }); |
1100 | 1098 | } else { // Shim |
1101 | 1099 | if (!global["dcodeIO"]) { |
|
0 commit comments