How to generate the right password format for Apache2 authentication in use with DBD and MySQL 5.1?

Posted by Walkman on Server Fault See other posts from Server Fault or by Walkman
Published on 2012-09-23T06:59:16Z Indexed on 2012/09/23 9:39 UTC
Read the original article Hit count: 256

I want to authenticate users for a folder from a MySQL 5.1 database with AuthType Basic.
The passwords are stored in plain text (they are not really passwords, so doesn't matter).
The password format for apache however only allows for SHA1, MD5 on Linux systems as described here.

How could I generate the right format with an SQL query ? Seems like apache format is a binary format with a lenght of 20, but the mysql SHA1 function return 40 long.

My SQL query is something like this:

SELECT CONCAT('{SHA}', BASE64_ENCODE(SHA1(access_key))) FROM user_access_keys INNER JOIN users ON user_access_keys.user_id = users.id WHERE name = %s

where base64_encode is a stored function (Mysql 5.1 doesn't have TO_BASE64 yet). This query returns a 61 byte BLOB which is not the same format that apache uses. How could I generate the same format ?

You can suggest other method for this too. The point is that I want to authenticate users from a MySQL5.1 database using plain text as password.

© Server Fault or respective owner

Related posts about apache2

Related posts about mysql