Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to configure an Apache server to accept case insensitive usernames for Basic Authentication?

Currently I'm using a pattern similar to this (in an included file) in my httpd.conf

<Location "/admin/">
   AuthType Basic
   AuthName "Admin Area"
   AuthUserFile "/path/to/auth-file"
   Require valid-user

Passwords should still be case sensitive.

share|improve this question
Did you ask the same question here and on SO ? – Denys Séguret May 28 '12 at 15:37
I thought it better suited to super user and deleted the one on SO – James Webster May 28 '12 at 15:45
up vote 2 down vote accepted

Let's assume you can make your auth-file usernames in the same case. Let's say they are uppercase.

To acheive what you want I would :

  1. use mod_rewrite with a RewriteMap that would call a python (or other) script
  2. in the script,
    1. base64 decode the Authentication header
    2. make the user name uppercase (the part before the colunm)
    3. base64 encode the Authentication header
  3. Use the new uppercase'd Authentication header

I don't have the setup to test it, but to give you a head start, here is a Python script that implements the idea (emphasis in clarity, it could be shorter) :


import base64
import sys
import string

#Get the header value
header = sys.stdin.readline()

#Base 64 decode it
authentication = base64.b64decode(header)

#Split username and password
userpass = authentication.split(':')

#Make username uppercase
userpass[0] = userpass[0].upper()

#Rebuild the authentication with the upper case username
authentication =  string.join(userpass,':')

#Send the base64 result back
print (base64.b64encode(authentication))

For a well known password :

$ echo QWxhZGRpbjpvcGVuIHNlc2FtZQ== | openssl base64 -d
Aladdin:open sesame

The script makes the username uppercase :

$ echo QWxhZGRpbjpvcGVuIHNlc2FtZQ== | python

$ echo QUxBRERJTjpvcGVuIHNlc2FtZQ== | openssl base64 -d
ALADDIN:open sesame

Caveat : this code will fail if you have non-ascii characters in the user name. étudiant78 becomes éTUDIANT78 on my machine.

share|improve this answer
Thank you, this helped. The second bit I understood no trouble coming from a programming background. The RewriteMap threw me for a bit, but your link and Google helped =] – James Webster May 30 '12 at 13:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .