Skip to content

Commit

Permalink
Validate (UTF8) compatibility with bcrypt, fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jun 8, 2014
1 parent d6bfbac commit 0e974f0
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ If the input has spaces inside, simply surround it with quotes.

Downloads
---------
* [Distributions](https://github.com/dcodeIO/bcrypt.js/tree/master/dist)
* [ZIP-Archive](https://github.com/dcodeIO/bcrypt.js/archive/master.zip)
* [Tarball](https://github.com/dcodeIO/bcrypt.js/tarball/master)

Expand Down
2 changes: 1 addition & 1 deletion bin/bcrypt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

var path = require("path"),
bcrypt = require(path.join(__dirname, '..', 'bcrypt.js')),
bcrypt = require(path.join(__dirname, '..', 'index.js')),
pkg = require(path.join(__dirname, '..', 'package.json'));

if (process.argv.length < 3) {
Expand Down
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright (c) 2012 Nevins Bartolomeo <[email protected]>
Copyright (c) 2012 Shane Girish <[email protected]>
Copyright (c) 2013 Daniel Wirtz <[email protected]>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
var path = require("path"),
bcrypt = require(path.join(__dirname, "dist", "bcrypt.js"));

module.exports = bcrypt;
11 changes: 6 additions & 5 deletions 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-pre",
"version": "1.0.0",
"author": "Daniel Wirtz <[email protected]>",
"contributors": [
"Shane Girish <[email protected]> (https://github.com/shaneGirish)",
Expand All @@ -26,18 +26,19 @@
"crypt",
"crypto"
],
"main": "./bcrypt.min.js",
"main": "index.js",
"dependencies": {},
"devDependencies": {
"testjs": "latest",
"preprocessor": "latest",
"closurecompiler": "latest"
"closurecompiler": "latest",
"bcrypt": "latest"
},
"license": "Apache-2.0",
"scripts": {
"test": "node node_modules/testjs/bin/testjs",
"build": "preprocess ./src/bcrypt.js ./src > ./bcrypt.js",
"compile": "ccjs bcrypt.js --warning_level=VERBOSE --compilation_level=ADVANCED_OPTIMIZATIONS --externs=externs/minimal-env.js > bcrypt.min.js",
"build": "preprocess ./src/bcrypt.js ./src > ./dist/bcrypt.js",
"compile": "ccjs dist/bcrypt.js --warning_level=VERBOSE --compilation_level=ADVANCED_OPTIMIZATIONS --externs=externs/minimal-env.js > dist/bcrypt.min.js",
"make": "npm run-script build && npm run-script compile && npm test"
}
}
150 changes: 150 additions & 0 deletions tests/quickbrown.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
Sentences that contain all letters commonly used in a language
--------------------------------------------------------------

Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/> -- 2012-04-11

This is an example of a plain-text file encoded in UTF-8.


Danish (da)
---------

Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen
Wolther spillede på xylofon.
(= Quiz contestants were eating strawbery with cream while Wolther
the circus clown played on xylophone.)

German (de)
-----------

Falsches Üben von Xylophonmusik quält jeden größeren Zwerg
(= Wrongful practicing of xylophone music tortures every larger dwarf)

Zwölf Boxkämpfer jagten Eva quer über den Sylter Deich
(= Twelve boxing fighters hunted Eva across the dike of Sylt)

Heizölrückstoßabdämpfung
(= fuel oil recoil absorber)
(jqvwxy missing, but all non-ASCII letters in one word)

Greek (el)
----------

Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο
(= No more shall I see acacias or myrtles in the golden clearing)

Ξεσκεπάζω τὴν ψυχοφθόρα βδελυγμία
(= I uncover the soul-destroying abhorrence)

English (en)
------------

The quick brown fox jumps over the lazy dog

Spanish (es)
------------

El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y
frío, añoraba a su querido cachorro.
(Contains every letter and every accent, but not every combination
of vowel + acute.)

French (fr)
-----------

Portez ce vieux whisky au juge blond qui fume sur son île intérieure, à
côté de l'alcôve ovoïde, où les bûches se consument dans l'âtre, ce
qui lui permet de penser à la cænogenèse de l'être dont il est question
dans la cause ambiguë entendue à Moÿ, dans un capharnaüm qui,
pense-t-il, diminue çà et là la qualité de son œuvre.

l'île exiguë
Où l'obèse jury mûr
Fête l'haï volapük,
Âne ex aéquo au whist,
Ôtez ce vœu déçu.

Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en
canoë au delà des îles, près du mälström où brûlent les novæ.

Irish Gaelic (ga)
-----------------

D'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh

Hungarian (hu)
--------------

Árvíztűrő tükörfúrógép
(= flood-proof mirror-drilling machine, only all non-ASCII letters)

Icelandic (is)
--------------

Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa

Sævör grét áðan því úlpan var ónýt
(some ASCII letters missing)

Japanese (jp)
-------------

Hiragana: (Iroha)

いろはにほへとちりぬるを
わかよたれそつねならむ
うゐのおくやまけふこえて
あさきゆめみしゑひもせす

Katakana:

イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン

Hebrew (iw)
-----------

? דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה

Polish (pl)
-----------

Pchnąć w tę łódź jeża lub ośm skrzyń fig
(= To push a hedgehog or eight bins of figs in this boat)

Russian (ru)
------------

В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!
(= Would a citrus live in the bushes of south? Yes, but only a fake one!)

Съешь же ещё этих мягких французских булок да выпей чаю
(= Eat some more of these fresh French loafs and have some tea)

Thai (th)
---------

[--------------------------|------------------------]
๏ เป็นมนุษย์สุดประเสริฐเลิศคุณค่า กว่าบรรดาฝูงสัตว์เดรัจฉาน
จงฝ่าฟันพัฒนาวิชาการ อย่าล้างผลาญฤๅเข่นฆ่าบีฑาใคร
ไม่ถือโทษโกรธแช่งซัดฮึดฮัดด่า หัดอภัยเหมือนกีฬาอัชฌาสัย
ปฏิบัติประพฤติกฎกำหนดใจ พูดจาให้จ๊ะๆ จ๋าๆ น่าฟังเอย ฯ

[The copyright for the Thai example is owned by The Computer
Association of Thailand under the Royal Patronage of His Majesty the
King.]

Turkish (tr)
------------

Pijamalı hasta, yağız şoföre çabucak güvendi.
(=Patient with pajamas, trusted swarthy driver quickly)


Special thanks to the people from all over the world who contributed
these sentences since 1999.

A much larger collection of such pangrams is now available at

http://en.wikipedia.org/wiki/List_of_pangrams

13 changes: 12 additions & 1 deletion tests/suite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var path = require("path"),
bcrypt = require(path.join(__dirname, '..', 'bcrypt.js'));
fs = require("fs"),
binding = require("bcrypt"),
bcrypt = require(path.join(__dirname, '..', 'index.js'));

module.exports = {

Expand Down Expand Up @@ -82,5 +84,14 @@ module.exports = {
var hash1 = bcrypt.hashSync("hello", bcrypt.genSaltSync());
test.equal(bcrypt.getRounds(hash1), 10);
test.done();
},

"compat": function(test) {
var pass = fs.readFileSync(path.join(__dirname, "quickbrown.txt"))+"",
salt = bcrypt.genSaltSync(),
hash1 = binding.hashSync(pass, salt),
hash2 = bcrypt.hashSync(pass, salt);
test.equal(hash1, hash2);
test.done();
}
};

0 comments on commit 0e974f0

Please sign in to comment.