$ 2y bcrypt hashes en Node.js

Estoy tratando con una vieja base de datos con$2y hashes He profundizado un poco en esto, también me topéel desbordamiento de la pila en la diferencia entre$2a y$2y.

Miré en el módulo de nodo parabcrypt que parece generar y comparar solo$2a hashes

https://github.com/ncb000gt/node.bcrypt.js/issues/175https://github.com/ncb000gt/node.bcrypt.js/issues/349https://github.com/ncb000gt/node.bcrypt.js/issues/213

Encontré un sitio web que genera$2y hash para que pueda probarlos conbcrypt.

http://aspirine.org/htpasswd_en.html

Aquí hay un ejemplo de un$2y hash de la cuerdahelloworld.

helloworld:$2yhttps://github.com/ncb000gt/node.bcrypt.js/issues/213tRM7x9gGKhcAmpeqKEdhj.qRWCr4qoV1FU9se0Crx2hkMVNL2ktEW

Parece que el módulo no tiene forma de validar$2y hashes

Aquí está mi prueba.

var Promise = require('bluebird')
var bcrypt = require('bcrypt')

var string = 'helloworld'

Promise.promisifyAll(bcrypt)

// bcrypt.genSalt(10, function(err, salt) {
//   bcrypt.hash(string, salt, function(err, hash) {
//     console.log(hash)
//   })
// })

var hashesGeneratedUsingBcryptModule = [
  '$2ahttps://github.com/ncb000gt/node.bcrypt.js/issues/2136ppmIdlNEPwxWJskPaQ7l.d2fblh.GO6JomzrcpiD/hxGPOXA3Bsq',
  '$2ahttps://github.com/ncb000gt/node.bcrypt.js/issues/213YmpoYCDHzdAPMbd9B8l48.hkSnylnAPbOym367FKIEPa0ixY.o4b.',
  '$2ahttps://github.com/ncb000gt/node.bcrypt.js/issues/213Xfy3OPurrZEmbmmO0x1wGuFMdRTlmOgEMS0geg4wTj1vKcvXXjk06',
  '$2ahttps://github.com/ncb000gt/node.bcrypt.js/issues/213mYgwmdPZjiEncp7Yh5UB1uyPkoyavxrYcOIzzY4mzSniGpI9RbhL.',
  '$2ahttps://github.com/ncb000gt/node.bcrypt.js/issues/213dkBVTe2A2DAn24PUq1GZYe7AqL8WQqwOi8ZWBJAauOg60sk44DkOC'
]

var hashesGeneratedUsingAspirineDotOrg = [
  '$2yhttps://github.com/ncb000gt/node.bcrypt.js/issues/213MKgpAXLJkwx5tpijWX99Qek2gf/irwvp5iSfxuFoDswIjMIbj2.Ma',
  '$2yhttps://github.com/ncb000gt/node.bcrypt.js/issues/213tRM7x9gGKhcAmpeqKEdhj.qRWCr4qoV1FU9se0Crx2hkMVNL2ktEW'
]

var hashesGeneratedUsingAspirineDotOrgSwippedYForA = [
  '$2ahttps://github.com/ncb000gt/node.bcrypt.js/issues/213MKgpAXLJkwx5tpijWX99Qek2gf/irwvp5iSfxuFoDswIjMIbj2.Ma',
  '$2ahttps://github.com/ncb000gt/node.bcrypt.js/issues/213tRM7x9gGKhcAmpeqKEdhj.qRWCr4qoV1FU9se0Crx2hkMVNL2ktEW'
]

hashesGeneratedUsingBcryptModule = hashesGeneratedUsingBcryptModule.map(hash => bcrypt.compareAsync(string, hash))
hashesGeneratedUsingAspirineDotOrg = hashesGeneratedUsingAspirineDotOrg.map(hash => bcrypt.compareAsync(string, hash))
hashesGeneratedUsingAspirineDotOrgSwippedYForA = hashesGeneratedUsingAspirineDotOrgSwippedYForA.map(hash => bcrypt.compareAsync(string, hash))

Promise.all(hashesGeneratedUsingBcryptModule)
.tap(() => console.log('hashesGeneratedUsingBcryptModule'))
.then(console.log)

Promise.all(hashesGeneratedUsingAspirineDotOrg)
.tap(() => console.log('hashesGeneratedUsingAspirineDotOrg'))
.then(console.log)

Promise.all(hashesGeneratedUsingAspirineDotOrgSwippedYForA)
.tap(() => console.log('hashesGeneratedUsingAspirineDotOrgSwippedYForA'))
.then(console.log)

Aquí están los resultados:

// hashesGeneratedUsingAspirineDotOrg
// [ false, false ]
// hashesGeneratedUsingBcryptModule
// [ true, true, true, true, true ]
// hashesGeneratedUsingAspirineDotOrgSwippedYForA
// [ false, false ]

Estoy perplejo de cómo puedo comparar$2y hashes en el nodo.

Hayotra pregunta / respuesta de desbordamiento de pila que dice que puedes cambiar el$2y a$2a Pero eso todavía falla para mí.

¡Actualizar!

Yo estaba usandoel generador incorrectamente porque es un.htpasswd generador de contraseñas debe ingresar el nombre de usuario y la contraseña en este formato.

reggi helloworld

Y la salida corresponde aquí:

reggi:$2yhttps://github.com/ncb000gt/node.bcrypt.js/issues/213iuC7GYH/h1Gl1aDmcpLFpeJXN9OZXZUYnaqD2NnGLQiVGQYBDtbtO

Antes de poner solo

helloword

Lo cual supongo que tiene una cadena vacía.

Con estos cambios cambiando ely a unaa trabaja enbcrypt. Ytwin-bcrypt solo funciona

Respuestas a la pregunta(1)

Su respuesta a la pregunta