Using RFID card to authenticate user

im trying to make django auth system to auth user based only on rfid tag like ‘1234567890’
I extended user model:

class RFID(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
RFID = models.CharField(max_length=30, unique=True)

create myBackend:

class MyBackend(BaseBackend):
    def authenticate(self, request, token=None):
        # Check the token and return a user.
            userRFID = RFID.objects.get(RFID=token)
            user = User.objects.get(pk=userRFID.user_id)
        except User.DoesNotExist:
            return None
        return user

    def get_user(self, user_id):
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None

edit settings:

AUTHENTICATION_BACKENDS= [‘myapp.myBackend’,‘django.contrib.auth.backends.ModelBackend’]

when trying to

u = authenticate(token=1234567890)

i get error:

ImportError: Module “myapp” does not define a “myBackend” attribute/class

if anyone have idea what to do with that…

Your class is defined as MyBackend, not myBackend.

thanks for pointing right direction. i have file called so it should be


Now it works from shell. going to make form for it and test in web.

Thanks a lot

Except that the standard convention for Python / Django classes is that class names should be capitalized. So the class is rightfully MyBackend.

Thanks i will remember that.

And Happy Birthday to You :grinning: