node.js – Migrating SHA1 passwords generated in PHP to Bcrypt in JavaScript-ThrowExceptions

Exception or error:

I’m coming at the encryption side of things more or less cold, and having spent a few days on this, I need help.

The plan is to mail the users, have them sign in, validate their password against SHA1, and then encrypt the supplied password in Bcrypt, replacing the existing password.

I have a “users” table that contains passwords generated by a combination of IonAuth and FlexiAuth in PHP, and a corresponding salt value for each password.

According to the configuration file for IonAuth, the passwords should be SHA1.

I’ve run a SHA1-encrypted password known to me through an existing Bcrypt method, and it too comes up with false for both password and password with salt, so I’ve at least eliminated Bcrypt as a possible algorithm.

So, for testing purposes, I’m using a known and valid username and password.

I’ve re-written the application in Vue, Node, Express and so on, and tried:

let password = passwordHash.verify(providedPassword + user.salt, user.password)
console.log("Users:password", password)

… but that comes up false for both password and password with salt.

I’m using the antique passwordHash module for Node, since I’ve not been able to find anything else, and I suspect this won’t work given it prepends its hash strings with “sha1”

For reference, the hashed password strings in the “users” table begin with: “$2a$08$…”, and those generated by Bcrypt in Node begin with: “$2a$10$…”

Any ideas?

How to solve:

I don’t know what you’re asking:

According to the configuration file for IonAuth, the passwords should be SHA1.

Ok. It can be whatever they decide; pig-latin if they want.

I’ve run a SHA1-encrypted password known to me through an existing Bcrypt method, and it too comes up with false for both password and password with salt, so I’ve at least eliminated Bcrypt as a possible algorithm.

SHA-1 is not encryption; it’s hashing. Did you run the SHA-1 hashed password through bcrypt? Or did you run the password through bcrypt?

and it too comes up with false for both password and password with salt

What do you mean salt? bcrypt supplies the salt. You don’t supply the salt.
Ok, so you’ve eliminated bcrypt.

But what’s the issue? Are you unable to login? Your underlying framework is unable to validate its own credentials? Are you getting an authentication error?

Short version: i have no idea what you’re doing.

But

  • regardless of what this Ion Framework says
  • regardless of SHA-1
  • regardless of salt or not(?!) salt
  • regardless of passing the password vs. the sha-1 hash of a password to bcrypt:

It seems like you’re asking to identify the hashed passwords being generated somewhere by someone.

Both:

  • $2a$08$…
  • $2a$10$…

are absolutely definitely bcrypt.

The first one is bcrypt with a cost factor of 8 (i.e. 28 rounds).
The second one is bcrypt with a cost factgor of 10 (i.e. 210 rounds).

Whatever it is, it should be using a cost factor of 12 please (so as to take ~250ms to generate).

So i would start by eliminating all the cruft “helpfully” supplied by this framework – and call bcrypt.

I’m not dealing with javascript ever again, nor do i know what bcrypt library this is. But every bcrypt library worth its salt has a function like:

String hash = bcrypt.hashPassword("hunter2", 12);

and

Boolean passwordMatch = bcrypt.verifyPassword("hunter2", hash);

The fact that someone is trying to append salt to a password:

providedPassword + user.salt

is absolutely wrong.

Regardless

If nothing else: those saved strings you showed are bcrypt.

  • $1$: MD5-based crypt (‘md5crypt’)
  • $2$: Blowfish-based crypt (‘bcrypt’)
  • $2a$: bcrypt; updated to document UTF8 and null terminator
  • $2b$: bcrypt; generated by OpenBSD without a bug in their earlier version
  • $2x$: bcrypt hashes generated by one buggy php implementation
  • $2y$: bcrypt hashes generated by one fixed php implementation
  • $sha1$: SHA-1-based crypt (‘sha1crypt’)
  • $5$: SHA-256-based crypt (‘sha256crypt’)
  • $6$: SHA-512-based crypt (‘sha512crypt’)

You say you’ve eliminated bcrypt.

I’m guaranteeing you bcrypt.

I suggest you get of this fancy framework, and use bcrypt directly. Once you’ve verified that you can correctly:

  • hash
  • store
  • verify

passwords using bcrypt, then you can try debugging this undocumented Ion Library.

Leave a Reply

Your email address will not be published. Required fields are marked *