<s> from django . contrib . auth import authenticate , login as auth_login , logout as auth_logout ; <EOL> from django . http import HttpResponse , HttpResponseRedirect <EOL> from django . conf import settings <EOL> class BasicAuthMiddleware ( object ) : <EOL> def process_request ( self , request ) : <EOL> authentication = request . META . get ( '<STR_LIT>' ) <EOL> if authentication : <EOL> ( authmeth , auth ) = authentication . split ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) <EOL> if '<STR_LIT>' == authmeth . lower ( ) : <EOL> auth = auth . strip ( ) . decode ( '<STR_LIT>' ) <EOL> username , password = auth . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> user = authenticate ( username = username , password = password ) <EOL> if user is not None : <EOL> if user . is_active : <EOL> auth_login ( request , user ) </s>
