'Allows the backend to clean the username, if the backend defines a
clean_username method.'

def clean_username(self, username, request):

    backend_str = request.session[auth.BACKEND_SESSION_KEY]
    backend = auth.load_backend(backend_str)
    try:
        username = backend.clean_username(username)
    except AttributeError:
        pass
    return username
