Hi there!
Does anyone know if EE 2.x does weird things to password hashes other than combining the salt and password and hashing that with an available SHA algorithm?
I’m updating some Ruby I wrote for EE 1.x which replicates ExpressionEngine’s username and password authentication, as I’d like to use my member database to authenticate users on an IRC server.
In EE 1.x, this was pretty simple: grab the user’s password hash from exp_members and compare it to the SHA-1 hex digest of their input.
EE 2.x has introduced environment-sensitive hash algorithms and password salts—both good things! And the code in system/expressionengine/libraries/Auth.php (as of ExpressionEngine 2.2.2) seems simple enough:
exp_members.salt and exp_members.password for the userexp_members.password (hopefully this is 128 bytes, which corresponds to SHA-512!)exp_members.salt and user’s password input (in that order, e.g. $salt.$password)exp_members.passwordHowever, something’s catching me out. My ExpressionEngine install sports 128-byte password hashes in exp_members, which points to ExpressionEngine using SHA-512 to hash things up. However, when I do the following in Ruby:
require "digest/sha2"
Digest::SHA512.hexdigest(salt_from_database + user_password_input)…the resulting hex digest is definitely not what’s in exp_members.password! Does anyone see anything obvious I’m missing? Is EE faking me out and using some other code entirely for generating password hashes? Maybe it’s truncating password length somewhere?
Any clues would be fantastic! Thanks! 😊
Just in case anyone’s wondering how I dealt with this, I thought about the problem for a while, and decided on a different tack. To avoid dealing with special characters in users’ passwords wreaking havoc with IRC’s text protocol (which has some character limitations), I generate a discrete IRC password for each member.
Not quite as slick, but I figured that since I’m already normalizing usernames, a password won’t add too much friction. Plus, it frees me from having to worry about EE’s password algorithm!
Okay, I thought I’d post a quick update for anyone who runs across this thread in the future. I revisited the issue with a clear mind this afternoon, and here’s a bit of Ruby that will authenticate a user against an ExpressionEngine >= 2.2.2 database:
https://gist.github.com/1233539
It replicates ExpressionEngine’s password hash byte size algorithm selection, and is overwhelmingly simple.
I’m not sure what the heck I was trying to do differently a month ago (I validated input and everything), but this lays that issue to rest for now!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.