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.

  • 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

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 uppercase_basic.py

$ 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.

  • 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
  • How would you configure Apache with RewriteMap and RewriteRule to modify the username (in step 1 and 3)? I have a program for step 2 but from stdin I only get URL paths. – bassjoe Feb 26 '20 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.