<s> from django . contrib . auth . models import User <EOL> from django . core . validators import validate_email <EOL> from django . contrib . auth . backends import ModelBackend <EOL> class EmailBackend ( ModelBackend ) : <EOL> """<STR_LIT>""" <EOL> supports_object_permissions = False <EOL> supports_anonymous_user = False <EOL> supports_inactive_user = False <EOL> def authenticate ( self , username = None , password = None ) : <EOL> try : <EOL> if validate_email ( username ) : <EOL> user = User . objects . get ( email = username ) <EOL> else : <EOL> user = User . objects . get ( username = username ) <EOL> except User . DoesNotExist : <EOL> return None <EOL> if user . check_password ( password ) : <EOL> return user <EOL> return None </s>
