Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
</Location>

Passwords should still be case sensitive.

share|improve this question
    
Did you ask the same question here and on SO ? –  dystroy 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
add comment

1 Answer

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) :

#!/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.

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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