We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Authenticating an external app against ExpressionEngine's member data

Development and Programming

Raws's avatar
Raws
4 posts
14 years ago
Raws's avatar Raws

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:

  1. Fetch exp_members.salt and exp_members.password for the user
  2. Choose a hash algorithm based on the byte length of exp_members.password (hopefully this is 128 bytes, which corresponds to SHA-512!)
  3. Concatenate exp_members.salt and user’s password input (in that order, e.g. $salt.$password)
  4. Hash the resulting string using the algorithm chosen in step two
  5. Compare the hashed string and exp_members.password

However, 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! 😊

       
Raws's avatar
Raws
4 posts
14 years ago
Raws's avatar Raws

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!

       
Raws's avatar
Raws
4 posts
14 years ago
Raws's avatar Raws

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!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.