Skip to content

Commit

Permalink
Do not throw if hash.length != 60
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jun 9, 2014
1 parent d793f7e commit acd062c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
![bcrypt.js - bcrypt in plain JavaScript](https://raw.github.com/dcodeIO/bcrypt.js/master/bcrypt.png)
===========
Optimized bcrypt in plain JavaScript with zero dependencies. Compiled through Closure Compiler using advanced
optimizations, 100% typed code. Fully compatible to [bcrypt](https://npmjs.org/package/bcrypt) and also working in the
browser.
optimizations, 100% typed code. Compatible to the C++ [bcrypt](https://npmjs.org/package/bcrypt) binding and also
working in the browser.

Features ![Build Status](https://travis-ci.org/dcodeIO/bcrypt.js.png?branch=master)
--------
Expand Down
24 changes: 11 additions & 13 deletions dist/bcrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@
*/
bcrypt.hashSync = function(s, salt) {
if (!salt) salt = GENSALT_DEFAULT_LOG2_ROUNDS;
if (typeof salt == 'number') {
if (typeof salt === 'number') {
salt = bcrypt.genSaltSync(salt);
}
return _hash(s, salt);
Expand All @@ -1003,10 +1003,10 @@
* @expose
*/
bcrypt.hash = function(s, salt, callback) {
if (typeof callback != 'function') {
if (typeof callback !== 'function') {
throw(new Error("Illegal 'callback': "+callback));
}
if (typeof salt == 'number') {
if (typeof salt === 'number') {
bcrypt.genSalt(salt, function(err, salt) {
_hash(s, salt, callback);
});
Expand All @@ -1024,12 +1024,10 @@
* @expose
*/
bcrypt.compareSync = function(s, hash) {
if(typeof s != "string" || typeof hash != "string") {
if(typeof s !== "string" || typeof hash !== "string") {
throw(new Error("Illegal argument types: "+(typeof s)+', '+(typeof hash)));
}
if(hash.length != 60) {
throw(new Error("Illegal hash length: "+hash.length+" != 60"));
}
if (hash.length !== 60) return false;
var comp = bcrypt.hashSync(s, hash.substr(0, hash.length-31));
var same = comp.length == hash.length;
var max_length = (comp.length < hash.length) ? comp.length : hash.length;
Expand All @@ -1053,7 +1051,7 @@
* @expose
*/
bcrypt.compare = function(s, hash, callback) {
if (typeof callback != 'function') {
if (typeof callback !== 'function') {
throw(new Error("Illegal 'callback': "+callback));
}
bcrypt.hash(s, hash.substr(0, 29), function(err, comp) {
Expand All @@ -1069,7 +1067,7 @@
* @expose
*/
bcrypt.getRounds = function(hash) {
if(typeof hash != "string") {
if(typeof hash !== "string") {
throw(new Error("Illegal type of 'hash': "+(typeof hash)));
}
return parseInt(hash.split("$")[2], 10);
Expand All @@ -1083,19 +1081,19 @@
* @expose
*/
bcrypt.getSalt = function(hash) {
if (typeof hash != 'string') {
if (typeof hash !== 'string') {
throw(new Error("Illegal type of 'hash': "+(typeof hash)));
}
if(hash.length != 60) {
if (hash.length !== 60) {
throw(new Error("Illegal hash length: "+hash.length+" != 60"));
}
return hash.substring(0, 29);
};

// Enable module loading if available
if (typeof module != 'undefined' && module["exports"]) { // CommonJS
if (typeof module !== 'undefined' && module["exports"]) { // CommonJS
module["exports"] = bcrypt;
} else if (typeof define != 'undefined' && define["amd"]) { // AMD
} else if (typeof define !== 'undefined' && define["amd"]) { // AMD
define("bcrypt", function() { return bcrypt; });
} else { // Shim
if (!global["dcodeIO"]) {
Expand Down
24 changes: 12 additions & 12 deletions dist/bcrypt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bcryptjs",
"description": "Optimized bcrypt in plain JavaScript with zero dependencies. 100% typed code. Fully compatible to 'bcrypt'.",
"version": "1.0.0",
"version": "1.0.1",
"author": "Daniel Wirtz <[email protected]>",
"contributors": [
"Shane Girish <[email protected]> (https://github.com/shaneGirish)",
Expand Down
Loading

0 comments on commit acd062c

Please sign in to comment.