4

I am trying to make a system to login to the Raspberry Pi with an RFID tag. I successfully connected the RFID reader RC522 module to the Raspberry Pi and I can retrieve the number of the tag and write a string into the RFID tag. Now I want to use this tag to log in to the Raspberry Pi. I know that my user should be associated with a tag ID, so I think I will develop a simple database (or simple file) to store my username and the tag ID.

My challenge now is to understand how I can talk with the console to perform a login. I don't know if there is any Python module to perform a login, or some feature to run the Linux command from Python.

Can anyone suggest something or give me any advice to move forward with this project?

2

The right way to do it would be getting pam_nfc module working with your RFID reader. Once installed, you'll have this pam-nfc-add command which can associate a user with a tag.

Another way is to write your own my_getty command which supports the reader, and refer to it from /lib/systemd/system/getty@.service instead of the original agetty. When the correct tag is presented, your script could call agetty --autologin username or login -f username to complete the login process (see here for details). Your script will be very sensitive security-wise (any bug you make would likely mean a security hole).

For GUI environments, you could also look into screensavers with lock/unlock commands. You would configure autologin for a specific user, then an autorun script would immediately lock the screen and wait for the RFID reader to detect a given tag before it finally unlocks the screen. This will not be very secure if there are race conditions which give the user an opportunity to interrupt the autorun script.

Another (but also not secure) way would be to connect the RFID reader to a small microcontroller with USB interface, like Arduino micro. The microcontroller would emulate the keyboard and issue the correct login sequence (typing username and password) when the reader detects the corresponding tag. Obviously, you'd have to update the microcontroller software every time any of the users change their password, and anybody who gets their hands on the microcontroller and the tag would be able to get the password in plain text.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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