javascript - Replicating Rails/AuthLogic Scrypt Hash Comparison on Node/Express Server -


i'm working on migrating older ruby-on-rails site node/express/react/redux, , i've run smack wall on authenticating users' existing passwords. site using authlogic(scrypt) authentication/password hashing, older account passwords still hashed sha512 authlogic algorithm.

i can't life of me figure out how replicate authlogic's scrypt algorithm in node. i've reviewed ruby source incantations authlogic , underlying scrypt package, gave me clues.

i'm using latest version of npm scrypt package (i've tried few others without discernable differences).

the stored hash looks this: 400$8$1d$3fbb0d3688d9da6d$5dd919ace6bdf946d48946e9dd61f0afc5116986433633e24e58809c12b5ce9a

the database stores unique salt parameter: fbmqa7ehfp5tdohnst

based on scrypt gem source, looks $ delimited segments cost factor , salt: n, r, p = args[0].split('$').map{ |x| x.to_i(16) } scrypt gem scrypt.rb source.

based on code, looks first 3 $ delimited bits "cost" factor scrypt , last 1 salt. have no idea why salt differs salt stored in database, or how should plugging them in. led me try:

    const n = parseint("400", 16)     const r = parseint("8", 16);     const p = parseint("1d", 16)     const result = scrypt.hashsync("[my password]",{"n":n,"r":r,"p":p}, 32, 3fbb0d3688d9da6d); 

the result of different hash database store, @ least right length. 80e302f9f8942ec9d81fe217c03730b5b8256b22cd91ad2dd2a448ec588ec390

so tried comparison:

     const comparision = scrypt.verifykdfsync(     "5dd919ace6bdf946d48946e9dd61f0afc5116986433633e24e58809c12b5ce9a",      "[mypassword]");  

but fails, telling me data not scrypt-hashed data. tried adding various bits of cost factor , salt, , without $ delimiters hash, no avail. tried turning hash buffer object, no avail. trying kdfsync above options failed (error computing derived key). online tools don't recognize stored hash scrypt hash.

help me ruby magicians (or else cyrptographic chops), you're hope(s).


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -