$ 2y bcrypt hashes no Node.js

Estou lidando com um banco de dados antigo com$2y hashes. Eu cavei isso um pouco, também tropeceio estouro da pilha na diferença entre$2a e$2y.

Eu olhei para o módulo nó parabcrypt que parece gerar e comparar apenas$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

Encontrei um site que gera$2y hashes para que eu possa testá-los combcrypt.

http://aspirine.org/htpasswd_en.html

Aqui está um exemplo de$2y hash da stringhelloworld.

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

Parece que o módulo não tem como validar$2y hashes.

Aqui está o meu teste.

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)

Aqui estão os resultados:

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

Estou perplexo em como posso comparar$2y hashes no nó.

outra pergunta / resposta do Stack Overflow que diz que você pode simplesmente mudar o$2y para$2a mas isso ainda falha para mim.

Atualizar!

Eu estava usandoo gerador incorretamente porque é um.htpasswd gerador de senhas, você deve inserir o nome de usuário e a senha neste formato.

reggi helloworld

E a saída corresponde aqui:

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

Antes de eu colocar apenas

helloword

Que eu estou assumindo hash uma string vazia.

Com essas mudanças, alterando oy para uma trabalha embcrypt. Etwin-bcrypt apenas funciona.

questionAnswers(1)

yourAnswerToTheQuestion