bcryptjs
Advanced tools
Comparing version 2.1.0 to 2.2.0
{ | ||
"name": "bcryptjs", | ||
"description": "Optimized bcrypt in plain JavaScript with zero dependencies.", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"main": "dist/bcrypt-isaac.js", | ||
@@ -6,0 +6,0 @@ "license": "New-BSD", |
@@ -34,3 +34,12 @@ /* | ||
*/ | ||
(function(global) { | ||
(function(global, factory) { | ||
/* AMD */ if (typeof define === 'function' && define["amd"]) | ||
define([], factory); | ||
/* CommonJS */ else if (typeof require === 'function' && typeof module === "object" && module && module["exports"]) | ||
module["exports"] = factory(); | ||
/* Global */ else | ||
(global["dcodeIO"] = global["dcodeIO"] || {})["bcrypt"] = factory(); | ||
}(this, function() { | ||
"use strict"; | ||
@@ -1173,10 +1182,23 @@ | ||
/** | ||
* Encodes a byte array to base64 with up to len bytes of input, using the custom bcrypt alphabet. | ||
* @function | ||
* @param {!Array.<number>} b Byte array | ||
* @param {number} len Maximum input length | ||
* @returns {string} | ||
* @expose | ||
*/ | ||
bcrypt.encodeBase64 = base64_encode; | ||
/* CommonJS */ if (typeof module !== 'undefined' && module["exports"]) | ||
module["exports"] = bcrypt; | ||
/* AMD */ else if (typeof define !== 'undefined' && define["amd"]) | ||
define(function() { return bcrypt; }); | ||
/* Global */ else | ||
(global["dcodeIO"] = global["dcodeIO"] || {})["bcrypt"] = bcrypt; | ||
/** | ||
* Decodes a base64 encoded string to up to len bytes of output, using the custom bcrypt alphabet. | ||
* @function | ||
* @param {string} s String to decode | ||
* @param {number} len Maximum output length | ||
* @returns {!Array.<number>} | ||
* @expose | ||
*/ | ||
bcrypt.decodeBase64 = base64_decode; | ||
})(this); | ||
return bcrypt; | ||
})); |
@@ -6,41 +6,41 @@ (function(){/* | ||
*/ | ||
function l(t){throw t;}var p=null; | ||
(function(t){function B(c){if("undefined"!==typeof module&&module&&module.exports)try{return require("crypto").randomBytes(c)}catch(a){}try{var b;(t.crypto||t.msCrypto).getRandomValues(b=new Uint32Array(c));return Array.prototype.slice.call(b)}catch(d){}x||l(Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative"));return x(c)}function F(c){var a=[],b=0;G.f(function(){return b>=c.length?p:c.charCodeAt(b++)},function(b){a.push(b)});return a} | ||
function y(c,a){var b=0,d=[],f,e;for((0>=a||a>c.length)&&l(Error("Illegal len: "+a));b<a;){f=c[b++]&255;d.push(u[f>>2&63]);f=(f&3)<<4;if(b>=a){d.push(u[f&63]);break}e=c[b++]&255;f|=e>>4&15;d.push(u[f&63]);f=(e&15)<<2;if(b>=a){d.push(u[f&63]);break}e=c[b++]&255;f|=e>>6&3;d.push(u[f&63]);d.push(u[e&63])}return d.join("")}function H(c){for(var a=0,b=c.length,d=0,f=[],e,k,h;a<b-1&&16>d;){h=c.charCodeAt(a++);e=h<r.length?r[h]:-1;h=c.charCodeAt(a++);k=h<r.length?r[h]:-1;if(-1==e||-1==k)break;h=e<<2>>>0; | ||
h|=(k&48)>>4;f.push(z(h));if(16<=++d||a>=b)break;h=c.charCodeAt(a++);e=h<r.length?r[h]:-1;if(-1==e)break;h=(k&15)<<4>>>0;h|=(e&60)>>2;f.push(z(h));if(16<=++d||a>=b)break;h=c.charCodeAt(a++);k=h<r.length?r[h]:-1;h=(e&3)<<6>>>0;h|=k;f.push(z(h));++d}c=[];for(a=0;a<d;a++)c.push(f[a].charCodeAt(0));return c}function w(c,a,b,d){for(var f,e=c[a],k=c[a+1],e=e^b[0],h=0;14>=h;)f=d[e>>24&255],f+=d[256|e>>16&255],f^=d[512|e>>8&255],f+=d[768|e&255],k^=f^b[++h],f=d[k>>24&255],f+=d[256|k>>16&255],f^=d[512|k>>8& | ||
255],f+=d[768|k&255],e^=f^b[++h];c[a]=k^b[17];c[a+1]=e;return c}function v(c,a){for(var b=0,d=0;4>b;++b)d=d<<8|c[a]&255,a=(a+1)%c.length;return{key:d,a:a}}function C(c,a,b){for(var d=0,f=[0,0],e=a.length,k=b.length,h,g=0;g<e;g++)h=v(c,d),d=h.a,a[g]^=h.key;for(g=0;g<e;g+=2)f=w(f,0,a,b),a[g]=f[0],a[g+1]=f[1];for(g=0;g<k;g+=2)f=w(f,0,a,b),b[g]=f[0],b[g+1]=f[1]}function I(c,a,b,d){for(var f=0,e=[0,0],k=b.length,h=d.length,g,m=0;m<k;m++)g=v(a,f),f=g.a,b[m]^=g.key;for(m=f=0;m<k;m+=2)g=v(c,f),f=g.a,e[0]^= | ||
g.key,g=v(c,f),f=g.a,e[1]^=g.key,e=w(e,0,b,d),b[m]=e[0],b[m+1]=e[1];for(m=0;m<h;m+=2)g=v(c,f),f=g.a,e[0]^=g.key,g=v(c,f),f=g.a,e[1]^=g.key,e=w(e,0,b,d),d[m]=e[0],d[m+1]=e[1]}function D(c,a,b,d,f){function e(){f&&f(q/b);if(q<b)for(var g=Date.now();q<b&&!(q+=1,C(c,m,n),C(a,m,n),100<Date.now()-g););else{for(q=0;64>q;q++)for(r=0;r<h>>1;r++)w(k,r<<1,m,n);g=[];for(q=0;q<h;q++)g.push((k[q]>>24&255)>>>0),g.push((k[q]>>16&255)>>>0),g.push((k[q]>>8&255)>>>0),g.push((k[q]&255)>>>0);if(d){d(p,g);return}return g}d&& | ||
s(e)}var k=E.slice(),h=k.length,g;if(4>b||31<b){g=Error("Illegal number of rounds (4-31): "+b);if(d){s(d.bind(this,g));return}l(g)}if(16!==a.length){g=Error("Illegal salt length: "+a.length+" != 16");if(d){s(d.bind(this,g));return}l(g)}b=1<<b;var m=J.slice(),n=K.slice(),q=0,r;I(a,c,m,n);if("undefined"!==typeof d)e();else for(;;)if("undefined"!==typeof(g=e()))return g||[]}function A(c,a,b,d){function f(a){var b=[];b.push("$2");"a"<=k&&b.push(k);b.push("$");10>g&&b.push("0");b.push(g.toString());b.push("$"); | ||
b.push(y(m,m.length));b.push(y(a,4*E.length-1));return b.join("")}var e;if("string"!==typeof c||"string"!==typeof a){e=Error("Invalid string / salt: Not a string");if(b){s(b.bind(this,e));return}l(e)}var k,h;if("$"!==a.charAt(0)||"2"!==a.charAt(1)){e=Error("Invalid salt version: "+a.substring(0,2));if(b){s(b.bind(this,e));return}l(e)}if("$"===a.charAt(2))k=String.fromCharCode(0),h=3;else{k=a.charAt(2);if("a"!==k&&"y"!==k||"$"!==a.charAt(3)){e=Error("Invalid salt revision: "+a.substring(2,4));if(b){s(b.bind(this, | ||
e));return}l(e)}h=4}if("$"<a.charAt(h+2)){e=Error("Missing salt rounds");if(b){s(b.bind(this,e));return}l(e)}var g=10*parseInt(a.substring(h,h+1),10)+parseInt(a.substring(h+1,h+2),10);a=a.substring(h+3,h+25);c=F(c+("a"<=k?"\x00":""));var m=H(a);if("undefined"==typeof b)return f(D(c,m,g));D(c,m,g,function(a,d){a?b(a,p):b(p,f(d))},d)}var n={},x=p;try{B(1)}catch(L){}x=p;n.l=function(c){x=c};n.genSaltSync=function(c,a){"undefined"===typeof c?c=10:"number"!==typeof c&&l(Error("Illegal arguments: "+typeof c+ | ||
", "+typeof a));(4>c||31<c)&&l(Error("Illegal number of rounds (4-31): "+c));var b=[];b.push("$2a$");10>c&&b.push("0");b.push(c.toString());b.push("$");b.push(y(B(16),16));return b.join("")};n.genSalt=function(c,a,b){"function"===typeof a&&(b=a,a=void 0);"function"===typeof c&&(b=c,c=10);"function"!==typeof b&&l(Error("Illegal callback: "+typeof b));"number"!==typeof c?s(b.bind(this,Error("Illegal arguments: "+typeof c))):s(function(){try{b(p,n.genSaltSync(c))}catch(a){b(a)}})};n.hashSync=function(c, | ||
a){"undefined"===typeof a&&(a=10);"number"===typeof a&&(a=n.genSaltSync(a));("string"!==typeof c||"string"!==typeof a)&&l(Error("Illegal arguments: "+typeof c+", "+typeof a));return A(c,a)};n.hash=function(c,a,b,d){"function"!==typeof b&&l(Error("Illegal callback: "+typeof b));"string"===typeof c&&"number"===typeof a?n.genSalt(a,function(a,e){A(c,e,b,d)}):"string"===typeof c&&"string"===typeof a?A(c,a,b,d):s(b.bind(this,Error("Illegal arguments: "+typeof c+", "+typeof a)))};n.compareSync=function(c, | ||
a){("string"!==typeof c||"string"!==typeof a)&&l(Error("Illegal arguments: "+typeof c+", "+typeof a));if(60!==a.length)return!1;for(var b=n.hashSync(c,a.substr(0,a.length-31)),d=b.length===a.length,f=b.length<a.length?b.length:a.length,e=0;e<f;++e)b.length>=e&&(a.length>=e&&b[e]!=a[e])&&(d=!1);return d};n.compare=function(c,a,b,d){"function"!==typeof b&&l(Error("Illegal callback: "+typeof b));"string"!==typeof c||"string"!==typeof a?s(b.bind(this,Error("Illegal arguments: "+typeof c+", "+typeof a))): | ||
n.hash(c,a.substr(0,29),function(d,c){b(d,a===c)},d)};n.getRounds=function(c){"string"!==typeof c&&l(Error("Illegal arguments: "+typeof c));return parseInt(c.split("$")[2],10)};n.getSalt=function(c){"string"!==typeof c&&l(Error("Illegal arguments: "+typeof c));60!==c.length&&l(Error("Illegal hash length: "+c.length+" != 60"));return c.substring(0,29)};var s="undefined"!==typeof process&&process&&"function"===typeof process.nextTick?"function"===typeof setImmediate?setImmediate:process.nextTick:setTimeout, | ||
u="./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),r=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,54,55,56,57,58,59,60,61,62,63,-1,-1,-1,-1,-1,-1,-1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,-1,-1,-1,-1,-1,-1,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,-1,-1,-1,-1,-1],z=String.fromCharCode,G=function(){var c={h:1114111, | ||
g:function(a,b){var d=p;"number"===typeof a&&(d=a,a=function(){return p});for(;d!==p||(d=a())!==p;)128>d?b(d&127):(2048>d?b(d>>6&31|192):(65536>d?b(d>>12&15|224):(b(d>>18&7|240),b(d>>12&63|128)),b(d>>6&63|128)),b(d&63|128)),d=p},e:function(a,b){function d(a){a=a.slice(0,a.indexOf(p));var b=Error(a.toString());b.name="TruncatedError";b.bytes=a;l(b)}for(var c,e,k,h;(c=a())!==p;)0===(c&128)?b(c):192===(c&224)?((e=a())===p&&d([c,e]),b((c&31)<<6|e&63)):224===(c&240)?(((e=a())===p||(k=a())===p)&&d([c,e, | ||
k]),b((c&15)<<12|(e&63)<<6|k&63)):240===(c&248)?(((e=a())===p||(k=a())===p||(h=a())===p)&&d([c,e,k,h]),b((c&7)<<18|(e&63)<<12|(k&63)<<6|h&63)):l(RangeError("Illegal starting byte: "+c))},b:function(a,b){for(var c,f=p;(c=f!==p?f:a())!==p;)55296<=c&&57343>=c&&(f=a())!==p&&56320<=f&&57343>=f?(b(1024*(c-55296)+f-56320+65536),f=p):b(c);f!==p&&b(f)},d:function(a,b){var c=p;"number"===typeof a&&(c=a,a=function(){return p});for(;c!==p||(c=a())!==p;)65535>=c?b(c):(c-=65536,b((c>>10)+55296),b(c%1024+56320)), | ||
c=p},f:function(a,b){c.b(a,function(a){c.g(a,b)})},k:function(a,b){c.e(a,function(a){c.d(a,b)})},c:function(a){return 128>a?1:2048>a?2:65536>a?3:4},j:function(a){for(var b,d=0;(b=a())!==p;)d+=c.c(b);return d},i:function(a){var b=0,d=0;c.b(a,function(a){++b;d+=c.c(a)});return[b,d]}};return c}();Date.now=Date.now||function(){return+new Date};var J=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069, | ||
3041331479,2450970073,2306472731],K=[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416,1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828, | ||
289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277,3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486, | ||
1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567,3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557, | ||
442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358,2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592, | ||
3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359,2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370, | ||
48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877,2845806497,146425753,1854211946,1266315497,3048417604,3681880366,3289982499,290971E4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509, | ||
1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511,2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880, | ||
613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807,616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303, | ||
2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133,1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385, | ||
1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019,1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030, | ||
4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190,2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055,3913112168, | ||
2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736,835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499, | ||
499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593,1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905, | ||
3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352,2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651, | ||
309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997,3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610, | ||
1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803,1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037, | ||
2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504,976866871,3556439503,2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200, | ||
2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353,2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241, | ||
3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263,1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891, | ||
3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409E3,2509781533,112762804,3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588, | ||
3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079,3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493, | ||
1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540,4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462],E=[1332899944,1700884034,1701343084,1684370003,1668446532, | ||
1869963892];"undefined"!==typeof module&&module.exports?module.exports=n:"undefined"!==typeof define&&define.amd?define(function(){return n}):(t.dcodeIO=t.dcodeIO||{}).bcrypt=n})(this);})(); | ||
function w(){function z(c){if("undefined"!==typeof module&&module&&module.exports)try{return require("crypto").randomBytes(c)}catch(a){}try{var b;(global.crypto||global.msCrypto).getRandomValues(b=new Uint32Array(c));return Array.prototype.slice.call(b)}catch(d){}if(!u)throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative");return u(c)}function E(c){var a=[],b=0;F.f(function(){return b>=c.length?null:c.charCodeAt(b++)},function(b){a.push(b)}); | ||
return a}function v(c,a){var b=0,d=[],g,f;if(0>=a||a>c.length)throw Error("Illegal len: "+a);for(;b<a;){g=c[b++]&255;d.push(r[g>>2&63]);g=(g&3)<<4;if(b>=a){d.push(r[g&63]);break}f=c[b++]&255;g|=f>>4&15;d.push(r[g&63]);g=(f&15)<<2;if(b>=a){d.push(r[g&63]);break}f=c[b++]&255;g|=f>>6&3;d.push(r[g&63]);d.push(r[f&63])}return d.join("")}function A(c,a){var b=0,d=c.length,g=0,f=[],h,k,e;if(0>=a)throw Error("Illegal len: "+a);for(;b<d-1&&g<a;){e=c.charCodeAt(b++);h=e<p.length?p[e]:-1;e=c.charCodeAt(b++); | ||
k=e<p.length?p[e]:-1;if(-1==h||-1==k)break;e=h<<2>>>0;e|=(k&48)>>4;f.push(x(e));if(++g>=a||b>=d)break;e=c.charCodeAt(b++);h=e<p.length?p[e]:-1;if(-1==h)break;e=(k&15)<<4>>>0;e|=(h&60)>>2;f.push(x(e));if(++g>=a||b>=d)break;e=c.charCodeAt(b++);k=e<p.length?p[e]:-1;e=(h&3)<<6>>>0;e|=k;f.push(x(e));++g}d=[];for(b=0;b<g;b++)d.push(f[b].charCodeAt(0));return d}function t(c,a,b,d){for(var g,f=c[a],h=c[a+1],f=f^b[0],k=0;14>=k;)g=d[f>>24&255],g+=d[256|f>>16&255],g^=d[512|f>>8&255],g+=d[768|f&255],h=h^g^b[++k], | ||
g=d[h>>24&255],g+=d[256|h>>16&255],g^=d[512|h>>8&255],g+=d[768|h&255],f=f^g^b[++k];c[a]=h^b[17];c[a+1]=f;return c}function s(c,a){for(var b=0,d=0;4>b;++b)d=d<<8|c[a]&255,a=(a+1)%c.length;return{key:d,a:a}}function B(c,a,b){for(var d=0,g=[0,0],f=a.length,h=b.length,k,e=0;e<f;e++)k=s(c,d),d=k.a,a[e]^=k.key;for(e=0;e<f;e+=2)g=t(g,0,a,b),a[e]=g[0],a[e+1]=g[1];for(e=0;e<h;e+=2)g=t(g,0,a,b),b[e]=g[0],b[e+1]=g[1]}function G(c,a,b,d){for(var g=0,f=[0,0],h=b.length,k=d.length,e,m=0;m<h;m++)e=s(a,g),g=e.a, | ||
b[m]^=e.key;for(m=g=0;m<h;m+=2)e=s(c,g),g=e.a,f[0]^=e.key,e=s(c,g),g=e.a,f[1]^=e.key,f=t(f,0,b,d),b[m]=f[0],b[m+1]=f[1];for(m=0;m<k;m+=2)e=s(c,g),g=e.a,f[0]^=e.key,e=s(c,g),g=e.a,f[1]^=e.key,f=t(f,0,b,d),d[m]=f[0],d[m+1]=f[1]}function C(c,a,b,d,g){function f(){g&&g(n/b);if(n<b)for(var e=Date.now();n<b&&!(n+=1,B(c,m,l),B(a,m,l),100<Date.now()-e););else{for(n=0;64>n;n++)for(p=0;p<k>>1;p++)t(h,p<<1,m,l);e=[];for(n=0;n<k;n++)e.push((h[n]>>24&255)>>>0),e.push((h[n]>>16&255)>>>0),e.push((h[n]>>8&255)>>> | ||
0),e.push((h[n]&255)>>>0);if(d){d(null,e);return}return e}d&&q(f)}var h=D.slice(),k=h.length,e;if(4>b||31<b){e=Error("Illegal number of rounds (4-31): "+b);if(d){q(d.bind(this,e));return}throw e;}if(16!==a.length){e=Error("Illegal salt length: "+a.length+" != 16");if(d){q(d.bind(this,e));return}throw e;}b=1<<b;var m=H.slice(),l=I.slice(),n=0,p;G(a,c,m,l);if("undefined"!==typeof d)f();else for(;;)if("undefined"!==typeof(e=f()))return e||[]}function y(c,a,b,d){function g(b){var a=[];a.push("$2");"a"<= | ||
f&&a.push(f);a.push("$");10>k&&a.push("0");a.push(k.toString());a.push("$");a.push(v(e,e.length));a.push(v(b,4*D.length-1));return a.join("")}if("string"!==typeof c||"string"!==typeof a){d=Error("Invalid string / salt: Not a string");if(b){q(b.bind(this,d));return}throw d;}var f,h;if("$"!==a.charAt(0)||"2"!==a.charAt(1)){d=Error("Invalid salt version: "+a.substring(0,2));if(b){q(b.bind(this,d));return}throw d;}if("$"===a.charAt(2))f=String.fromCharCode(0),h=3;else{f=a.charAt(2);if("a"!==f&&"y"!== | ||
f||"$"!==a.charAt(3)){d=Error("Invalid salt revision: "+a.substring(2,4));if(b){q(b.bind(this,d));return}throw d;}h=4}if("$"<a.charAt(h+2)){d=Error("Missing salt rounds");if(b){q(b.bind(this,d));return}throw d;}var k=10*parseInt(a.substring(h,h+1),10)+parseInt(a.substring(h+1,h+2),10);a=a.substring(h+3,h+25);c=E(c+("a"<=f?"\x00":""));var e=A(a,16);if("undefined"==typeof b)return g(C(c,e,k));C(c,e,k,function(a,d){a?b(a,null):b(null,g(d))},d)}var l={},u=null;try{z(1)}catch(J){}u=null;l.l=function(c){u= | ||
c};l.genSaltSync=function(c,a){if("undefined"===typeof c)c=10;else if("number"!==typeof c)throw Error("Illegal arguments: "+typeof c+", "+typeof a);if(4>c||31<c)throw Error("Illegal number of rounds (4-31): "+c);var b=[];b.push("$2a$");10>c&&b.push("0");b.push(c.toString());b.push("$");b.push(v(z(16),16));return b.join("")};l.genSalt=function(c,a,b){"function"===typeof a&&(b=a,a=void 0);"function"===typeof c&&(b=c,c=10);if("function"!==typeof b)throw Error("Illegal callback: "+typeof b);"number"!== | ||
typeof c?q(b.bind(this,Error("Illegal arguments: "+typeof c))):q(function(){try{b(null,l.genSaltSync(c))}catch(a){b(a)}})};l.hashSync=function(c,a){"undefined"===typeof a&&(a=10);"number"===typeof a&&(a=l.genSaltSync(a));if("string"!==typeof c||"string"!==typeof a)throw Error("Illegal arguments: "+typeof c+", "+typeof a);return y(c,a)};l.hash=function(c,a,b,d){if("function"!==typeof b)throw Error("Illegal callback: "+typeof b);"string"===typeof c&&"number"===typeof a?l.genSalt(a,function(a,f){y(c, | ||
f,b,d)}):"string"===typeof c&&"string"===typeof a?y(c,a,b,d):q(b.bind(this,Error("Illegal arguments: "+typeof c+", "+typeof a)))};l.compareSync=function(c,a){if("string"!==typeof c||"string"!==typeof a)throw Error("Illegal arguments: "+typeof c+", "+typeof a);if(60!==a.length)return!1;for(var b=l.hashSync(c,a.substr(0,a.length-31)),d=b.length===a.length,g=b.length<a.length?b.length:a.length,f=0;f<g;++f)b.length>=f&&a.length>=f&&b[f]!=a[f]&&(d=!1);return d};l.compare=function(c,a,b,d){if("function"!== | ||
typeof b)throw Error("Illegal callback: "+typeof b);"string"!==typeof c||"string"!==typeof a?q(b.bind(this,Error("Illegal arguments: "+typeof c+", "+typeof a))):l.hash(c,a.substr(0,29),function(d,c){b(d,a===c)},d)};l.getRounds=function(c){if("string"!==typeof c)throw Error("Illegal arguments: "+typeof c);return parseInt(c.split("$")[2],10)};l.getSalt=function(c){if("string"!==typeof c)throw Error("Illegal arguments: "+typeof c);if(60!==c.length)throw Error("Illegal hash length: "+c.length+" != 60"); | ||
return c.substring(0,29)};var q="undefined"!==typeof process&&process&&"function"===typeof process.nextTick?"function"===typeof setImmediate?setImmediate:process.nextTick:setTimeout,r="./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split(""),p=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,54,55,56,57,58,59,60,61,62,63,-1,-1,-1,-1,-1,-1,-1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, | ||
20,21,22,23,24,25,26,27,-1,-1,-1,-1,-1,-1,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,-1,-1,-1,-1,-1],x=String.fromCharCode,F=function(){var c={h:1114111,g:function(a,b){var d=null;"number"===typeof a&&(d=a,a=function(){return null});for(;null!==d||null!==(d=a());)128>d?b(d&127):(2048>d?b(d>>6&31|192):(65536>d?b(d>>12&15|224):(b(d>>18&7|240),b(d>>12&63|128)),b(d>>6&63|128)),b(d&63|128)),d=null},e:function(a,b){function d(a){a=a.slice(0,a.indexOf(null));var b=Error(a.toString()); | ||
b.name="TruncatedError";b.bytes=a;throw b;}for(var c,f,h,k;null!==(c=a());)if(0===(c&128))b(c);else if(192===(c&224))null===(f=a())&&d([c,f]),b((c&31)<<6|f&63);else if(224===(c&240))null!==(f=a())&&null!==(h=a())||d([c,f,h]),b((c&15)<<12|(f&63)<<6|h&63);else if(240===(c&248))null!==(f=a())&&null!==(h=a())&&null!==(k=a())||d([c,f,h,k]),b((c&7)<<18|(f&63)<<12|(h&63)<<6|k&63);else throw RangeError("Illegal starting byte: "+c);},b:function(a,b){for(var d,c=null;null!==(d=null!==c?c:a());)55296<=d&&57343>= | ||
d&&null!==(c=a())&&56320<=c&&57343>=c?(b(1024*(d-55296)+c-56320+65536),c=null):b(d);null!==c&&b(c)},d:function(a,b){var c=null;"number"===typeof a&&(c=a,a=function(){return null});for(;null!==c||null!==(c=a());)65535>=c?b(c):(c-=65536,b((c>>10)+55296),b(c%1024+56320)),c=null},f:function(a,b){c.b(a,function(a){c.g(a,b)})},k:function(a,b){c.e(a,function(a){c.d(a,b)})},c:function(a){return 128>a?1:2048>a?2:65536>a?3:4},j:function(a){for(var b,d=0;null!==(b=a());)d+=c.c(b);return d},i:function(a){var b= | ||
0,d=0;c.b(a,function(a){++b;d+=c.c(a)});return[b,d]}};return c}();Date.now=Date.now||function(){return+new Date};var H=[608135816,2242054355,320440878,57701188,2752067618,698298832,137296536,3964562569,1160258022,953160567,3193202383,887688300,3232508343,3380367581,1065670069,3041331479,2450970073,2306472731],I=[3509652390,2564797868,805139163,3491422135,3101798381,1780907670,3128725573,4046225305,614570311,3012652279,134345442,2240740374,1667834072,1901547113,2757295779,4103290238,227898511,1921955416, | ||
1904987480,2182433518,2069144605,3260701109,2620446009,720527379,3318853667,677414384,3393288472,3101374703,2390351024,1614419982,1822297739,2954791486,3608508353,3174124327,2024746970,1432378464,3864339955,2857741204,1464375394,1676153920,1439316330,715854006,3033291828,289532110,2706671279,2087905683,3018724369,1668267050,732546397,1947742710,3462151702,2609353502,2950085171,1814351708,2050118529,680887927,999245976,1800124847,3300911131,1713906067,1641548236,4213287313,1216130144,1575780402,4018429277, | ||
3917837745,3693486850,3949271944,596196993,3549867205,258830323,2213823033,772490370,2760122372,1774776394,2652871518,566650946,4142492826,1728879713,2882767088,1783734482,3629395816,2517608232,2874225571,1861159788,326777828,3124490320,2130389656,2716951837,967770486,1724537150,2185432712,2364442137,1164943284,2105845187,998989502,3765401048,2244026483,1075463327,1455516326,1322494562,910128902,469688178,1117454909,936433444,3490320968,3675253459,1240580251,122909385,2157517691,634681816,4142456567, | ||
3825094682,3061402683,2540495037,79693498,3249098678,1084186820,1583128258,426386531,1761308591,1047286709,322548459,995290223,1845252383,2603652396,3431023940,2942221577,3202600964,3727903485,1712269319,422464435,3234572375,1170764815,3523960633,3117677531,1434042557,442511882,3600875718,1076654713,1738483198,4213154764,2393238008,3677496056,1014306527,4251020053,793779912,2902807211,842905082,4246964064,1395751752,1040244610,2656851899,3396308128,445077038,3742853595,3577915638,679411651,2892444358, | ||
2354009459,1767581616,3150600392,3791627101,3102740896,284835224,4246832056,1258075500,768725851,2589189241,3069724005,3532540348,1274779536,3789419226,2764799539,1660621633,3471099624,4011903706,913787905,3497959166,737222580,2514213453,2928710040,3937242737,1804850592,3499020752,2949064160,2386320175,2390070455,2415321851,4061277028,2290661394,2416832540,1336762016,1754252060,3520065937,3014181293,791618072,3188594551,3933548030,2332172193,3852520463,3043980520,413987798,3465142937,3030929376,4245938359, | ||
2093235073,3534596313,375366246,2157278981,2479649556,555357303,3870105701,2008414854,3344188149,4221384143,3956125452,2067696032,3594591187,2921233993,2428461,544322398,577241275,1471733935,610547355,4027169054,1432588573,1507829418,2025931657,3646575487,545086370,48609733,2200306550,1653985193,298326376,1316178497,3007786442,2064951626,458293330,2589141269,3591329599,3164325604,727753846,2179363840,146436021,1461446943,4069977195,705550613,3059967265,3887724982,4281599278,3313849956,1404054877, | ||
2845806497,146425753,1854211946,1266315497,3048417604,3681880366,3289982499,290971E4,1235738493,2632868024,2414719590,3970600049,1771706367,1449415276,3266420449,422970021,1963543593,2690192192,3826793022,1062508698,1531092325,1804592342,2583117782,2714934279,4024971509,1294809318,4028980673,1289560198,2221992742,1669523910,35572830,157838143,1052438473,1016535060,1802137761,1753167236,1386275462,3080475397,2857371447,1040679964,2145300060,2390574316,1461121720,2956646967,4031777805,4028374788,33600511, | ||
2920084762,1018524850,629373528,3691585981,3515945977,2091462646,2486323059,586499841,988145025,935516892,3367335476,2599673255,2839830854,265290510,3972581182,2759138881,3795373465,1005194799,847297441,406762289,1314163512,1332590856,1866599683,4127851711,750260880,613907577,1450815602,3165620655,3734664991,3650291728,3012275730,3704569646,1427272223,778793252,1343938022,2676280711,2052605720,1946737175,3164576444,3914038668,3967478842,3682934266,1661551462,3294938066,4011595847,840292616,3712170807, | ||
616741398,312560963,711312465,1351876610,322626781,1910503582,271666773,2175563734,1594956187,70604529,3617834859,1007753275,1495573769,4069517037,2549218298,2663038764,504708206,2263041392,3941167025,2249088522,1514023603,1998579484,1312622330,694541497,2582060303,2151582166,1382467621,776784248,2618340202,3323268794,2497899128,2784771155,503983604,4076293799,907881277,423175695,432175456,1378068232,4145222326,3954048622,3938656102,3820766613,2793130115,2977904593,26017576,3274890735,3194772133, | ||
1700274565,1756076034,4006520079,3677328699,720338349,1533947780,354530856,688349552,3973924725,1637815568,332179504,3949051286,53804574,2852348879,3044236432,1282449977,3583942155,3416972820,4006381244,1617046695,2628476075,3002303598,1686838959,431878346,2686675385,1700445008,1080580658,1009431731,832498133,3223435511,2605976345,2271191193,2516031870,1648197032,4164389018,2548247927,300782431,375919233,238389289,3353747414,2531188641,2019080857,1475708069,455242339,2609103871,448939670,3451063019, | ||
1395535956,2413381860,1841049896,1491858159,885456874,4264095073,4001119347,1565136089,3898914787,1108368660,540939232,1173283510,2745871338,3681308437,4207628240,3343053890,4016749493,1699691293,1103962373,3625875870,2256883143,3830138730,1031889488,3479347698,1535977030,4236805024,3251091107,2132092099,1774941330,1199868427,1452454533,157007616,2904115357,342012276,595725824,1480756522,206960106,497939518,591360097,863170706,2375253569,3596610801,1814182875,2094937945,3421402208,1082520231,3463918190, | ||
2785509508,435703966,3908032597,1641649973,2842273706,3305899714,1510255612,2148256476,2655287854,3276092548,4258621189,236887753,3681803219,274041037,1734335097,3815195456,3317970021,1899903192,1026095262,4050517792,356393447,2410691914,3873677099,3682840055,3913112168,2491498743,4132185628,2489919796,1091903735,1979897079,3170134830,3567386728,3557303409,857797738,1136121015,1342202287,507115054,2535736646,337727348,3213592640,1301675037,2528481711,1895095763,1721773893,3216771564,62756741,2142006736, | ||
835421444,2531993523,1442658625,3659876326,2882144922,676362277,1392781812,170690266,3921047035,1759253602,3611846912,1745797284,664899054,1329594018,3901205900,3045908486,2062866102,2865634940,3543621612,3464012697,1080764994,553557557,3656615353,3996768171,991055499,499776247,1265440854,648242737,3940784050,980351604,3713745714,1749149687,3396870395,4211799374,3640570775,1161844396,3125318951,1431517754,545492359,4268468663,3499529547,1437099964,2702547544,3433638243,2581715763,2787789398,1060185593, | ||
1593081372,2418618748,4260947970,69676912,2159744348,86519011,2512459080,3838209314,1220612927,3339683548,133810670,1090789135,1078426020,1569222167,845107691,3583754449,4072456591,1091646820,628848692,1613405280,3757631651,526609435,236106946,48312990,2942717905,3402727701,1797494240,859738849,992217954,4005476642,2243076622,3870952857,3732016268,765654824,3490871365,2511836413,1685915746,3888969200,1414112111,2273134842,3281911079,4080962846,172450625,2569994100,980381355,4109958455,2819808352, | ||
2716589560,2568741196,3681446669,3329971472,1835478071,660984891,3704678404,4045999559,3422617507,3040415634,1762651403,1719377915,3470491036,2693910283,3642056355,3138596744,1364962596,2073328063,1983633131,926494387,3423689081,2150032023,4096667949,1749200295,3328846651,309677260,2016342300,1779581495,3079819751,111262694,1274766160,443224088,298511866,1025883608,3806446537,1145181785,168956806,3641502830,3584813610,1689216846,3666258015,3200248200,1692713982,2646376535,4042768518,1618508792,1610833997, | ||
3523052358,4130873264,2001055236,3610705100,2202168115,4028541809,2961195399,1006657119,2006996926,3186142756,1430667929,3210227297,1314452623,4074634658,4101304120,2273951170,1399257539,3367210612,3027628629,1190975929,2062231137,2333990788,2221543033,2438960610,1181637006,548689776,2362791313,3372408396,3104550113,3145860560,296247880,1970579870,3078560182,3769228297,1714227617,3291629107,3898220290,166772364,1251581989,493813264,448347421,195405023,2709975567,677966185,3703036547,1463355134,2715995803, | ||
1338867538,1343315457,2802222074,2684532164,233230375,2599980071,2000651841,3277868038,1638401717,4028070440,3237316320,6314154,819756386,300326615,590932579,1405279636,3267499572,3150704214,2428286686,3959192993,3461946742,1862657033,1266418056,963775037,2089974820,2263052895,1917689273,448879540,3550394620,3981727096,150775221,3627908307,1303187396,508620638,2975983352,2726630617,1817252668,1876281319,1457606340,908771278,3720792119,3617206836,2455994898,1729034894,1080033504,976866871,3556439503, | ||
2881648439,1522871579,1555064734,1336096578,3548522304,2579274686,3574697629,3205460757,3593280638,3338716283,3079412587,564236357,2993598910,1781952180,1464380207,3163844217,3332601554,1699332808,1393555694,1183702653,3581086237,1288719814,691649499,2847557200,2895455976,3193889540,2717570544,1781354906,1676643554,2592534050,3230253752,1126444790,2770207658,2633158820,2210423226,2615765581,2414155088,3127139286,673620729,2805611233,1269405062,4015350505,3341807571,4149409754,1057255273,2012875353, | ||
2162469141,2276492801,2601117357,993977747,3918593370,2654263191,753973209,36408145,2530585658,25011837,3520020182,2088578344,530523599,2918365339,1524020338,1518925132,3760827505,3759777254,1202760957,3985898139,3906192525,674977740,4174734889,2031300136,2019492241,3983892565,4153806404,3822280332,352677332,2297720250,60907813,90501309,3286998549,1016092578,2535922412,2839152426,457141659,509813237,4120667899,652014361,1966332200,2975202805,55981186,2327461051,676427537,3255491064,2882294119,3433927263, | ||
1307055953,942726286,933058658,2468411793,3933900994,4215176142,1361170020,2001714738,2830558078,3274259782,1222529897,1679025792,2729314320,3714953764,1770335741,151462246,3013232138,1682292957,1483529935,471910574,1539241949,458788160,3436315007,1807016891,3718408830,978976581,1043663428,3165965781,1927990952,4200891579,2372276910,3208408903,3533431907,1412390302,2931980059,4132332400,1947078029,3881505623,4168226417,2941484381,1077988104,1320477388,886195818,18198404,3786409E3,2509781533,112762804, | ||
3463356488,1866414978,891333506,18488651,661792760,1628790961,3885187036,3141171499,876946877,2693282273,1372485963,791857591,2686433993,3759982718,3167212022,3472953795,2716379847,445679433,3561995674,3504004811,3574258232,54117162,3331405415,2381918588,3769707343,4154350007,1140177722,4074052095,668550556,3214352940,367459370,261225585,2610173221,4209349473,3468074219,3265815641,314222801,3066103646,3808782860,282218597,3406013506,3773591054,379116347,1285071038,846784868,2669647154,3771962079, | ||
3550491691,2305946142,453669953,1268987020,3317592352,3279303384,3744833421,2610507566,3859509063,266596637,3847019092,517658769,3462560207,3443424879,370717030,4247526661,2224018117,4143653529,4112773975,2788324899,2477274417,1456262402,2901442914,1517677493,1846949527,2295493580,3734397586,2176403920,1280348187,1908823572,3871786941,846861322,1172426758,3287448474,3383383037,1655181056,3139813346,901632758,1897031941,2986607138,3066810236,3447102507,1393639104,373351379,950779232,625454576,3124240540, | ||
4148612726,2007998917,544563296,2244738638,2330496472,2058025392,1291430526,424198748,50039436,29584100,3605783033,2429876329,2791104160,1057563949,3255363231,3075367218,3463963227,1469046755,985887462],D=[1332899944,1700884034,1701343084,1684370003,1668446532,1869963892];l.encodeBase64=v;l.decodeBase64=A;return l} | ||
"function"===typeof define&&define.amd?define([],w):"function"===typeof require&&"object"===typeof module&&module&&module.exports?module.exports=w():(this.dcodeIO=this.dcodeIO||{}).bcrypt=w();})(); |
Distributions | ||
============= | ||
bcrypt.js is available either without a random fallback or with ISAAC: | ||
bcrypt.js is available as the following distributions: | ||
### Standard | ||
* **[bcrypt.js](https://github.com/dcodeIO/bcrypt.js/blob/master/dist/bcrypt.js)** | ||
contains the commented source code. | ||
This version relies on the crypto module under node.js and the Web Crypto API in the browser, providing you with the | ||
option to specify a random fallback for browser environments that do not support the Web Crypto API natively (use | ||
`bcrypt.setRandomFallback`). | ||
* **[bcrypt.min.js](https://github.com/dcodeIO/bcrypt.js/blob/master/dist/bcrypt.min.js)** | ||
has been compiled with Closure Compiler using advanced optimizations. | ||
* **[bcrypt.js](https://github.com/dcodeIO/bcrypt.js/blob/master/dist/bcrypt.js)** | ||
contains the commented source code. | ||
* **[bcrypt.min.map](https://github.com/dcodeIO/bcrypt.js/blob/master/dist/bcrypt.min.map)** | ||
contains the source map generated by Closure Compiler. | ||
* **[bcrypt.min.js](https://github.com/dcodeIO/bcrypt.js/blob/master/dist/bcrypt.min.js)** | ||
has been compiled with Closure Compiler using advanced optimizations. | ||
* **[bcrypt.min.js.gz](https://github.com/dcodeIO/bcrypt.js/blob/master/dist/bcrypt.min.js.gz)** | ||
has also been gzipped using `-9`. |
{ | ||
"name": "bcryptjs", | ||
"description": "Optimized bcrypt in plain JavaScript with zero dependencies. Compatible to 'bcrypt'.", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
@@ -48,5 +48,6 @@ "contributors": [ | ||
"build": "node scripts/build.js", | ||
"compile": "ccjs dist/bcrypt.js --compilation_level=ADVANCED_OPTIMIZATIONS --externs=externs/minimal-env.js --output_wrapper=\"(function(){%output%})();\" > dist/bcrypt.min.js", | ||
"compile": "node node_modules/closurecompiler/bin/ccjs dist/bcrypt.js --compilation_level=ADVANCED_OPTIMIZATIONS --create_source_map=dist/bcrypt.min.map --externs=externs/minimal-env.js --output_wrapper=\"(function(){%output%})();\" > dist/bcrypt.min.js", | ||
"compress": "gzip -c -9 dist/bcrypt.min.js > dist/bcrypt.min.js.gz", | ||
"make": "npm run-script build && npm run-script compile && npm test" | ||
} | ||
} |
@@ -130,4 +130,7 @@ ![bcrypt.js - Optimized bcrypt in JavaScript with zero dependencies](https://raw.github.com/dcodeIO/bcrypt.js/master/bcrypt.png) | ||
| **@see** | | http://nodejs.org/api/crypto.html | ||
| **@see** | | http://www.w3.org/TR/WebCryptoAPI/ | ||
| **@see** | | http://www.w3.org/TR/WebCryptoAPI/ | ||
**Hint:** You might use [isaac.js](https://github.com/rubycon/isaac.js) as a CSPRNG but you still have to make sure to | ||
seed it properly. | ||
### genSaltSync(rounds=, seed_length=) | ||
@@ -134,0 +137,0 @@ |
@@ -20,3 +20,3 @@ var MetaScript = require("metascript"), | ||
path.join(distDir, "bcrypt.js"), | ||
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "bcrypt.js")), filename, scope, srcDir) | ||
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.js")), filename, scope, srcDir) | ||
); | ||
@@ -23,0 +23,0 @@ |
@@ -1,292 +0,253 @@ | ||
//? if (typeof ISAAC === 'undefined') ISAAC = false; | ||
/* | ||
Copyright (c) 2012 Nevins Bartolomeo <nevins.bartolomeo@gmail.com> | ||
Copyright (c) 2012 Shane Girish <shaneGirish@gmail.com> | ||
Copyright (c) 2014 Daniel Wirtz <dcode@dcode.io> | ||
/** | ||
* bcrypt namespace. | ||
* @type {Object.<string,*>} | ||
*/ | ||
var bcrypt = {}; | ||
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. | ||
/** | ||
* The random implementation to use as a fallback. | ||
* @type {?function(number):!Array.<number>} | ||
* @inner | ||
*/ | ||
var randomFallback = null; | ||
/** | ||
//? if (ISAAC) | ||
* @license bcrypt-isaac.js (c) 2013 Daniel Wirtz <dcode@dcode.io> | ||
//? else | ||
* @license bcrypt.js (c) 2013 Daniel Wirtz <dcode@dcode.io> | ||
* Released under the Apache License, Version 2.0 | ||
* see: https://github.com/dcodeIO/bcrypt.js for details | ||
* Generates cryptographically secure random bytes. | ||
* @function | ||
* @param {number} len Bytes length | ||
* @returns {!Array.<number>} Random bytes | ||
* @throws {Error} If no random implementation is available | ||
* @inner | ||
*/ | ||
(function(global) { | ||
"use strict"; | ||
/** | ||
* bcrypt namespace. | ||
* @type {Object.<string,*>} | ||
*/ | ||
var bcrypt = {}; | ||
/** | ||
* The random implementation to use as a fallback. | ||
* @type {?function(number):!Array.<number>} | ||
* @inner | ||
*/ | ||
var randomFallback = null; | ||
/** | ||
* Generates cryptographically secure random bytes. | ||
* @function | ||
* @param {number} len Bytes length | ||
* @returns {!Array.<number>} Random bytes | ||
* @throws {Error} If no random implementation is available | ||
* @inner | ||
*/ | ||
function random(len) { | ||
/* node */ if (typeof module !== 'undefined' && module && module['exports']) | ||
try { | ||
return require("crypto")['randomBytes'](len); | ||
} catch (e) {} | ||
/* WCA */ try { | ||
var a; (global['crypto']||global['msCrypto'])['getRandomValues'](a = new Uint32Array(len)); | ||
return Array.prototype.slice.call(a); | ||
function random(len) { | ||
/* node */ if (typeof module !== 'undefined' && module && module['exports']) | ||
try { | ||
return require("crypto")['randomBytes'](len); | ||
} catch (e) {} | ||
/* fallback */ if (!randomFallback) | ||
throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative"); | ||
return randomFallback(len); | ||
} | ||
// Test if any secure randomness source is available | ||
var randomAvailable = false; | ||
try { | ||
random(1); | ||
randomAvailable = true; | ||
/* WCA */ try { | ||
var a; (global['crypto']||global['msCrypto'])['getRandomValues'](a = new Uint32Array(len)); | ||
return Array.prototype.slice.call(a); | ||
} catch (e) {} | ||
/* fallback */ if (!randomFallback) | ||
throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative"); | ||
return randomFallback(len); | ||
} | ||
// Default fallback, if any | ||
randomFallback = /*? if (ISAAC) { */function(len) { | ||
for (var a=[], i=0; i<len; ++i) | ||
a[i] = ((0.5 + isaac() * 2.3283064365386963e-10) * 256) | 0; | ||
return a; | ||
};/*? } else { */null;/*? }*/ | ||
// Test if any secure randomness source is available | ||
var randomAvailable = false; | ||
try { | ||
random(1); | ||
randomAvailable = true; | ||
} catch (e) {} | ||
// Default fallback, if any | ||
randomFallback = /*? if (ISAAC) { */function(len) { | ||
for (var a=[], i=0; i<len; ++i) | ||
a[i] = ((0.5 + isaac() * 2.3283064365386963e-10) * 256) | 0; | ||
return a; | ||
};/*? } else { */null;/*? }*/ | ||
/** | ||
* Sets the pseudo random number generator to use as a fallback if neither node's `crypto` module nor the Web Crypto | ||
* API is available. Please note: It is highly important that the PRNG used is cryptographically secure and that it | ||
* is seeded properly! | ||
* @param {?function(number):!Array.<number>} random Function taking the number of bytes to generate as its | ||
* sole argument, returning the corresponding array of cryptographically secure random byte values. | ||
* @see http://nodejs.org/api/crypto.html | ||
* @see http://www.w3.org/TR/WebCryptoAPI/ | ||
*/ | ||
bcrypt.setRandomFallback = function(random) { | ||
randomFallback = random; | ||
}; | ||
/** | ||
* Synchronously generates a salt. | ||
* @param {number=} rounds Number of rounds to use, defaults to 10 if omitted | ||
* @param {number=} seed_length Not supported. | ||
* @returns {string} Resulting salt | ||
* @throws {Error} If a random fallback is required but not set | ||
* @expose | ||
*/ | ||
bcrypt.genSaltSync = function(rounds, seed_length) { | ||
if (typeof rounds === 'undefined') | ||
rounds = GENSALT_DEFAULT_LOG2_ROUNDS; | ||
else if (typeof rounds !== 'number') | ||
throw Error("Illegal arguments: "+(typeof rounds)+", "+(typeof seed_length)); | ||
if (rounds < 4 || rounds > 31) | ||
throw Error("Illegal number of rounds (4-31): "+rounds); | ||
var salt = []; | ||
salt.push("$2a$"); | ||
if (rounds < 10) | ||
salt.push("0"); | ||
salt.push(rounds.toString()); | ||
salt.push('$'); | ||
salt.push(base64_encode(random(BCRYPT_SALT_LEN), BCRYPT_SALT_LEN)); // May throw | ||
return salt.join(''); | ||
}; | ||
/** | ||
* Sets the pseudo random number generator to use as a fallback if neither node's `crypto` module nor the Web Crypto | ||
* API is available. Please note: It is highly important that the PRNG used is cryptographically secure and that it | ||
* is seeded properly! | ||
* @param {?function(number):!Array.<number>} random Function taking the number of bytes to generate as its | ||
* sole argument, returning the corresponding array of cryptographically secure random byte values. | ||
* @see http://nodejs.org/api/crypto.html | ||
* @see http://www.w3.org/TR/WebCryptoAPI/ | ||
*/ | ||
bcrypt.setRandomFallback = function(random) { | ||
randomFallback = random; | ||
}; | ||
/** | ||
* Asynchronously generates a salt. | ||
* @param {(number|function(Error, string=))=} rounds Number of rounds to use, defaults to 10 if omitted | ||
* @param {(number|function(Error, string=))=} seed_length Not supported. | ||
* @param {function(Error, string=)=} callback Callback receiving the error, if any, and the resulting salt | ||
* @expose | ||
*/ | ||
bcrypt.genSalt = function(rounds, seed_length, callback) { | ||
if (typeof seed_length === 'function') | ||
callback = seed_length, | ||
seed_length = undefined; // Not supported. | ||
if (typeof rounds === 'function') | ||
callback = rounds, | ||
rounds = GENSALT_DEFAULT_LOG2_ROUNDS; | ||
if (typeof callback !== 'function') | ||
throw Error("Illegal callback: "+typeof(callback)); | ||
if (typeof rounds !== 'number') { | ||
nextTick(callback.bind(this, Error("Illegal arguments: "+(typeof rounds)))); | ||
return; | ||
/** | ||
* Synchronously generates a salt. | ||
* @param {number=} rounds Number of rounds to use, defaults to 10 if omitted | ||
* @param {number=} seed_length Not supported. | ||
* @returns {string} Resulting salt | ||
* @throws {Error} If a random fallback is required but not set | ||
* @expose | ||
*/ | ||
bcrypt.genSaltSync = function(rounds, seed_length) { | ||
if (typeof rounds === 'undefined') | ||
rounds = GENSALT_DEFAULT_LOG2_ROUNDS; | ||
else if (typeof rounds !== 'number') | ||
throw Error("Illegal arguments: "+(typeof rounds)+", "+(typeof seed_length)); | ||
if (rounds < 4 || rounds > 31) | ||
throw Error("Illegal number of rounds (4-31): "+rounds); | ||
var salt = []; | ||
salt.push("$2a$"); | ||
if (rounds < 10) | ||
salt.push("0"); | ||
salt.push(rounds.toString()); | ||
salt.push('$'); | ||
salt.push(base64_encode(random(BCRYPT_SALT_LEN), BCRYPT_SALT_LEN)); // May throw | ||
return salt.join(''); | ||
}; | ||
/** | ||
* Asynchronously generates a salt. | ||
* @param {(number|function(Error, string=))=} rounds Number of rounds to use, defaults to 10 if omitted | ||
* @param {(number|function(Error, string=))=} seed_length Not supported. | ||
* @param {function(Error, string=)=} callback Callback receiving the error, if any, and the resulting salt | ||
* @expose | ||
*/ | ||
bcrypt.genSalt = function(rounds, seed_length, callback) { | ||
if (typeof seed_length === 'function') | ||
callback = seed_length, | ||
seed_length = undefined; // Not supported. | ||
if (typeof rounds === 'function') | ||
callback = rounds, | ||
rounds = GENSALT_DEFAULT_LOG2_ROUNDS; | ||
if (typeof callback !== 'function') | ||
throw Error("Illegal callback: "+typeof(callback)); | ||
if (typeof rounds !== 'number') { | ||
nextTick(callback.bind(this, Error("Illegal arguments: "+(typeof rounds)))); | ||
return; | ||
} | ||
nextTick(function() { // Pretty thin, but salting is fast enough | ||
try { | ||
callback(null, bcrypt.genSaltSync(rounds)); | ||
} catch (err) { | ||
callback(err); | ||
} | ||
nextTick(function() { // Pretty thin, but salting is fast enough | ||
try { | ||
callback(null, bcrypt.genSaltSync(rounds)); | ||
} catch (err) { | ||
callback(err); | ||
} | ||
}); | ||
}; | ||
}); | ||
}; | ||
/** | ||
* Synchronously generates a hash for the given string. | ||
* @param {string} s String to hash | ||
* @param {(number|string)=} salt Salt length to generate or salt to use, default to 10 | ||
* @returns {string} Resulting hash | ||
* @expose | ||
*/ | ||
bcrypt.hashSync = function(s, salt) { | ||
if (typeof salt === 'undefined') | ||
salt = GENSALT_DEFAULT_LOG2_ROUNDS; | ||
if (typeof salt === 'number') | ||
salt = bcrypt.genSaltSync(salt); | ||
if (typeof s !== 'string' || typeof salt !== 'string') | ||
throw Error("Illegal arguments: "+(typeof s)+', '+(typeof salt)); | ||
return _hash(s, salt); | ||
}; | ||
/** | ||
* Synchronously generates a hash for the given string. | ||
* @param {string} s String to hash | ||
* @param {(number|string)=} salt Salt length to generate or salt to use, default to 10 | ||
* @returns {string} Resulting hash | ||
* @expose | ||
*/ | ||
bcrypt.hashSync = function(s, salt) { | ||
if (typeof salt === 'undefined') | ||
salt = GENSALT_DEFAULT_LOG2_ROUNDS; | ||
if (typeof salt === 'number') | ||
salt = bcrypt.genSaltSync(salt); | ||
if (typeof s !== 'string' || typeof salt !== 'string') | ||
throw Error("Illegal arguments: "+(typeof s)+', '+(typeof salt)); | ||
return _hash(s, salt); | ||
}; | ||
/** | ||
* Asynchronously generates a hash for the given string. | ||
* @param {string} s String to hash | ||
* @param {number|string} salt Salt length to generate or salt to use | ||
* @param {function(Error, string=)} callback Callback receiving the error, if any, and the resulting hash | ||
* @param {function(number)=} progressCallback Callback successively called with the percentage of rounds completed | ||
* (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms. | ||
* @expose | ||
*/ | ||
bcrypt.hash = function(s, salt, callback, progressCallback) { | ||
if (typeof callback !== 'function') | ||
throw Error("Illegal callback: "+typeof(callback)); | ||
if (typeof s === 'string' && typeof salt === 'number') | ||
bcrypt.genSalt(salt, function(err, salt) { | ||
_hash(s, salt, callback, progressCallback); | ||
}); | ||
else if (typeof s === 'string' && typeof salt === 'string') | ||
/** | ||
* Asynchronously generates a hash for the given string. | ||
* @param {string} s String to hash | ||
* @param {number|string} salt Salt length to generate or salt to use | ||
* @param {function(Error, string=)} callback Callback receiving the error, if any, and the resulting hash | ||
* @param {function(number)=} progressCallback Callback successively called with the percentage of rounds completed | ||
* (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms. | ||
* @expose | ||
*/ | ||
bcrypt.hash = function(s, salt, callback, progressCallback) { | ||
if (typeof callback !== 'function') | ||
throw Error("Illegal callback: "+typeof(callback)); | ||
if (typeof s === 'string' && typeof salt === 'number') | ||
bcrypt.genSalt(salt, function(err, salt) { | ||
_hash(s, salt, callback, progressCallback); | ||
else | ||
nextTick(callback.bind(this, Error("Illegal arguments: "+(typeof s)+', '+(typeof salt)))); | ||
}; | ||
}); | ||
else if (typeof s === 'string' && typeof salt === 'string') | ||
_hash(s, salt, callback, progressCallback); | ||
else | ||
nextTick(callback.bind(this, Error("Illegal arguments: "+(typeof s)+', '+(typeof salt)))); | ||
}; | ||
/** | ||
* Synchronously tests a string against a hash. | ||
* @param {string} s String to compare | ||
* @param {string} hash Hash to test against | ||
* @returns {boolean} true if matching, otherwise false | ||
* @throws {Error} If an argument is illegal | ||
* @expose | ||
*/ | ||
bcrypt.compareSync = function(s, hash) { | ||
if (typeof s !== "string" || typeof hash !== "string") | ||
throw Error("Illegal arguments: "+(typeof s)+', '+(typeof hash)); | ||
if (hash.length !== 60) | ||
return false; | ||
var comp = bcrypt.hashSync(s, hash.substr(0, hash.length-31)), | ||
same = comp.length === hash.length, | ||
max_length = (comp.length < hash.length) ? comp.length : hash.length; | ||
// to prevent timing attacks, should check entire string | ||
// don't exit after found to be false | ||
for (var i = 0; i < max_length; ++i) | ||
if (comp.length >= i && hash.length >= i && comp[i] != hash[i]) | ||
same = false; | ||
return same; | ||
}; | ||
/** | ||
* Synchronously tests a string against a hash. | ||
* @param {string} s String to compare | ||
* @param {string} hash Hash to test against | ||
* @returns {boolean} true if matching, otherwise false | ||
* @throws {Error} If an argument is illegal | ||
* @expose | ||
*/ | ||
bcrypt.compareSync = function(s, hash) { | ||
if (typeof s !== "string" || typeof hash !== "string") | ||
throw Error("Illegal arguments: "+(typeof s)+', '+(typeof hash)); | ||
if (hash.length !== 60) | ||
return false; | ||
var comp = bcrypt.hashSync(s, hash.substr(0, hash.length-31)), | ||
same = comp.length === hash.length, | ||
max_length = (comp.length < hash.length) ? comp.length : hash.length; | ||
// to prevent timing attacks, should check entire string | ||
// don't exit after found to be false | ||
for (var i = 0; i < max_length; ++i) | ||
if (comp.length >= i && hash.length >= i && comp[i] != hash[i]) | ||
same = false; | ||
return same; | ||
}; | ||
/** | ||
* Asynchronously compares the given data against the given hash. | ||
* @param {string} s Data to compare | ||
* @param {string} hash Data to be compared to | ||
* @param {function(Error, boolean)} callback Callback receiving the error, if any, otherwise the result | ||
* @param {function(number)=} progressCallback Callback successively called with the percentage of rounds completed | ||
* (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms. | ||
* @throws {Error} If the callback argument is invalid | ||
* @expose | ||
*/ | ||
bcrypt.compare = function(s, hash, callback, progressCallback) { | ||
if (typeof callback !== 'function') | ||
throw Error("Illegal callback: "+typeof(callback)); | ||
if (typeof s !== "string" || typeof hash !== "string") { | ||
nextTick(callback.bind(this, Error("Illegal arguments: "+(typeof s)+', '+(typeof hash)))); | ||
return; | ||
} | ||
bcrypt.hash(s, hash.substr(0, 29), function(err, comp) { | ||
callback(err, hash === comp); | ||
}, progressCallback); | ||
}; | ||
/** | ||
* Asynchronously compares the given data against the given hash. | ||
* @param {string} s Data to compare | ||
* @param {string} hash Data to be compared to | ||
* @param {function(Error, boolean)} callback Callback receiving the error, if any, otherwise the result | ||
* @param {function(number)=} progressCallback Callback successively called with the percentage of rounds completed | ||
* (0.0 - 1.0), maximally once per `MAX_EXECUTION_TIME = 100` ms. | ||
* @throws {Error} If the callback argument is invalid | ||
* @expose | ||
*/ | ||
bcrypt.compare = function(s, hash, callback, progressCallback) { | ||
if (typeof callback !== 'function') | ||
throw Error("Illegal callback: "+typeof(callback)); | ||
if (typeof s !== "string" || typeof hash !== "string") { | ||
nextTick(callback.bind(this, Error("Illegal arguments: "+(typeof s)+', '+(typeof hash)))); | ||
return; | ||
} | ||
bcrypt.hash(s, hash.substr(0, 29), function(err, comp) { | ||
callback(err, hash === comp); | ||
}, progressCallback); | ||
}; | ||
/** | ||
* Gets the number of rounds used to encrypt the specified hash. | ||
* @param {string} hash Hash to extract the used number of rounds from | ||
* @returns {number} Number of rounds used | ||
* @throws {Error} If hash is not a string | ||
* @expose | ||
*/ | ||
bcrypt.getRounds = function(hash) { | ||
if (typeof hash !== "string") | ||
throw Error("Illegal arguments: "+(typeof hash)); | ||
return parseInt(hash.split("$")[2], 10); | ||
}; | ||
/** | ||
* Gets the number of rounds used to encrypt the specified hash. | ||
* @param {string} hash Hash to extract the used number of rounds from | ||
* @returns {number} Number of rounds used | ||
* @throws {Error} If hash is not a string | ||
* @expose | ||
*/ | ||
bcrypt.getRounds = function(hash) { | ||
if (typeof hash !== "string") | ||
throw Error("Illegal arguments: "+(typeof hash)); | ||
return parseInt(hash.split("$")[2], 10); | ||
}; | ||
/** | ||
* Gets the salt portion from a hash. Does not validate the hash. | ||
* @param {string} hash Hash to extract the salt from | ||
* @returns {string} Extracted salt part | ||
* @throws {Error} If `hash` is not a string or otherwise invalid | ||
* @expose | ||
*/ | ||
bcrypt.getSalt = function(hash) { | ||
if (typeof hash !== 'string') | ||
throw Error("Illegal arguments: "+(typeof hash)); | ||
if (hash.length !== 60) | ||
throw Error("Illegal hash length: "+hash.length+" != 60"); | ||
return hash.substring(0, 29); | ||
}; | ||
/** | ||
* Gets the salt portion from a hash. Does not validate the hash. | ||
* @param {string} hash Hash to extract the salt from | ||
* @returns {string} Extracted salt part | ||
* @throws {Error} If `hash` is not a string or otherwise invalid | ||
* @expose | ||
*/ | ||
bcrypt.getSalt = function(hash) { | ||
if (typeof hash !== 'string') | ||
throw Error("Illegal arguments: "+(typeof hash)); | ||
if (hash.length !== 60) | ||
throw Error("Illegal hash length: "+hash.length+" != 60"); | ||
return hash.substring(0, 29); | ||
}; | ||
//? include("bcrypt/util.js"); | ||
//? include("bcrypt/util.js"); | ||
//? include("bcrypt/impl.js"); | ||
//? include("bcrypt/impl.js"); | ||
//? if (ISAAC) { | ||
//? include("bcrypt/prng/accum.js"); | ||
/** | ||
* Encodes a byte array to base64 with up to len bytes of input, using the custom bcrypt alphabet. | ||
* @function | ||
* @param {!Array.<number>} b Byte array | ||
* @param {number} len Maximum input length | ||
* @returns {string} | ||
* @expose | ||
*/ | ||
bcrypt.encodeBase64 = base64_encode; | ||
// Start accumulating | ||
if (!randomAvailable) | ||
accum.start(); | ||
//? include("bcrypt/prng/isaac.js"); | ||
//? } | ||
/* CommonJS */ if (typeof module !== 'undefined' && module["exports"]) | ||
module["exports"] = bcrypt; | ||
/* AMD */ else if (typeof define !== 'undefined' && define["amd"]) | ||
define(function() { return bcrypt; }); | ||
/* Global */ else | ||
(global["dcodeIO"] = global["dcodeIO"] || {})["bcrypt"] = bcrypt; | ||
})(this); | ||
/** | ||
* Decodes a base64 encoded string to up to len bytes of output, using the custom bcrypt alphabet. | ||
* @function | ||
* @param {string} s String to decode | ||
* @param {number} len Maximum output length | ||
* @returns {!Array.<number>} | ||
* @expose | ||
*/ | ||
bcrypt.decodeBase64 = base64_decode; |
@@ -125,11 +125,15 @@ var path = require("path"), | ||
}); | ||
}/*, | ||
}, | ||
"isaac": function(test) { | ||
for (var i= 0, n; i<999999; ++i) { | ||
n = ((0.5 + isaac() * 2.3283064365386963e-10) * 256) | 0; | ||
test.ok(n === n && n >= 0 && n < 256 && n % 1 === 0); | ||
} | ||
"encodeBase64": function(test) { | ||
var str = bcrypt.encodeBase64([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10], 16); | ||
test.strictEqual(str, "..CA.uOD/eaGAOmJB.yMBu"); | ||
test.done(); | ||
}*/ | ||
}, | ||
"decodeBase64": function(test) { | ||
var bytes = bcrypt.decodeBase64("..CA.uOD/eaGAOmJB.yMBv.", 16); | ||
test.deepEqual(bytes, [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]); | ||
test.done(); | ||
} | ||
}; |
200591
27
2809
241