Case insensitive Basic Authentication with Apache
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 :
- use mod_rewrite with a
RewriteMap
that would call a python (or other) script - in the script,
- base64 decode the Authentication header
- make the user name uppercase (the part before the colunm)
- base64 encode the Authentication header
- 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) :
#!/usr/bin/python
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
QUxBRERJTjpvcGVuIHNlc2FtZQ==
$ 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.