NFC Computer Unlocker

97,552

608

44

Introduction: NFC Computer Unlocker


Quit pulling your hair out over incorrect passwords. Using an Arduino Leonardo and Adafruit's NFC shield, you can unlock your computer with an NFC card. The Arduino reads the NFC card's unique identifier and once it receives the correct one, it uses the Arduino Leonardo's keyboard emulation feature to type a password. 

Step 1: Parts Needed

You will need the following parts for this build:
Arduino Leonardo
Adafruit's NFC Shield
NFC Tag (included with shield)
A Small Piece of Hookup Wire
You will optionally need:
More NFC Tags (available from Adafruit)
Tools Needed:
Sharp Knife
Soldering Iron
Wire Cutters and Strippers
Computer
Micro USB Cable

Step 2: Hardware

You will need to solder the header pins to the shield and retrace the jumper for this project to work. 
Step One:
Solder the header pins to the shield. The easiest way is to insert the header pins into the Arduino and place the shield on top of the header pins. Solder the header pins on the top of the shield. 
Step Two: 
Cut the jumper between the IRQ pin and Pin 2 using a sharp knife. We need to do this because the NFC shield doesn't communicate with the Arduino Leonardo at Pin 2.  Use a multimeter to check continuity between the two pins. 
Step Three: 
Strip about 1/2" of insulation off of each end of a small piece of wire. Then solder this wire between IRQ and pin 6 on the Arduino. 
Once all of that is done, the NFC shield is ready to communicate with the Arduino. 

Step 3: Software

The software that needs to be uploaded to the Arduino is below. Make sure that you have the Adafruit NFC Library installed. Learn more about that here.

#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>


#define IRQ 6 // this trace must be cut and rewired!
#define RESET 8

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

//////////////////////////////////// SETUP

void setup() {
  // set up Serial library at 9600 bps
  Serial.begin(9600);

  // find Adafruit RFID/NFC shield
  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

  // configure board to read RFID tags
  nfc.SAMConfig();
Keyboard.begin(); //initiate the Keyboard
}

/////////////////////////////////// LOOP

unsigned digit = 0;

void loop() {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
  uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

  // wait for RFID card to show up!
  Serial.println("Waiting for an ISO14443A Card ...");


  // Wait for an ISO14443A type cards (Mifare, etc.). When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  uint32_t cardidentifier = 0;

  if (success) {
    // Found a card!

    Serial.print("Card detected #");
    // turn the four byte UID of a mifare classic into a single variable #
    cardidentifier = uid[3];
    cardidentifier <<= 8; cardidentifier |= uid[2];
    cardidentifier <<= 8; cardidentifier |= uid[1];
    cardidentifier <<= 8; cardidentifier |= uid[0];
    Serial.println(cardidentifier);


    if (cardidentifier == 606061173) {
      Keyboard.write('m');
      Keyboard.write('y');
       Keyboard.write('p');
        Keyboard.write('a');
         Keyboard.write('s');
          Keyboard.write('s');
           Keyboard.write('w');
            Keyboard.write('o');
             Keyboard.write('r');
              Keyboard.write('d');
              delay(5000); //makes sure the password isn't repeated
    }
  }
}


Once the code is uploaded, open the serial monitor set at 9600 baud. Place the NFC tag on the shield for a second and then remove it. The serial monitor should say, "Card detected #card number." Copy the unique card number and paste it in the cardidentifier == 606061173 statement in the code. The card number will replace 606061173. Then change the keyboard.write statements to spell out your password one letter at a time. Reupload the code and whenever the NFC tag is placed on the shield it will type your password for you. 

Step 4: 3D Printing

You can optionally 3D print an enclosure to house the Arduino and to mount it onto a desk. The .stl file is on this page. The two screw holes on the case allow a long screw to pass through. This is meant to be mounted underneath a desk. The NFC signal should work as long as the table is thinner than 5cm. 

Arduino Contest

Participated in the
Arduino Contest

Full Spectrum Laser Contest

Participated in the
Full Spectrum Laser Contest

Be the First to Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Automation Contest

      Automation Contest
    • Make it Glow Contest

      Make it Glow Contest

    44 Comments

    0
    NathanH8
    NathanH8

    6 years ago on Introduction

    I added some simple AES encryption using Davy Landman's AESLib for Arduino; please see my repo here: https://github.com/nhenderson/Arduino-NFC-Computer-Unlocker.

    0
    The Electrodog Show
    The Electrodog Show

    Reply 6 years ago on Introduction

    I just got to your code and have some questions. Could you give me your email please?

    0
    colinj
    colinj

    6 years ago on Step 4

    This looks like a nice idea. And it is a great example of the keyboard function of the Leonardo.

    My one concern is that you are storing the password in clear text in the arduino code. If some stole the arduino they'd have your password.

    Have you thought about using the NFC reader as part of a two-factor authentication system? So you would need both the card and a password?

    0
    The Electrodog Show
    The Electrodog Show

    Reply 6 years ago on Introduction

    As far as I know you can't read the code off an Arduino. Also if you 3D print the case it will be bolted to your table :-)

    0
    MihneaV
    MihneaV

    Reply 4 years ago

    I think that he meant to say:Someone might steal the arduino,and trigger the kev presses,then in something like notepad,they'll see the password being typed out for them.

    0
    RyanB139
    RyanB139

    4 years ago

    so the code says uploading then just sits there and never finishes-anyone have that problem?

    0
    npro6979
    npro6979

    5 years ago

    I'm having some problems I hope you can help me with on this project.

    I'm getting this error message.

    Keyboard_NFC_Unlocker:61: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

    Keyboard.write('m'); //update with your password!

    ^

    exit status 1

    'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

    Adding #include <keyboard.h> just tells me the file can't be found. Any help would be awesome. Thanks!

    0
    RyanB139
    RyanB139

    Reply 4 years ago

    Did you ever get answer or figure this out?

    0
    RyanB139
    RyanB139

    4 years ago

    I have same keyboard error as npro6979

    Can you provide any guidance on how to fix this please?

    0
    PryceM
    PryceM

    5 years ago

    This might be a dumb question, but I don't see how the arduino is connected to the computer after it is programmed? Does the USB have to remain constantly plugged in to work? Or is it programmed to send the password over wifi?

    0
    RonzMan95
    RonzMan95

    5 years ago on Introduction

    Hi, will this work with a phone as an NFC tag?

    0
    RonzMan95
    RonzMan95

    Reply 5 years ago on Introduction

    The reason I asked was, like any nfc card or sticker.... there is an identifier to verify it. Just like the card or sticker, doesn't the phone also have a unique number that we use for payment or file transfer? So in theory the technology should be able to work with few tweaks right? Just was an idea

    0
    KadirÖ1
    KadirÖ1

    Reply 5 years ago on Introduction

    Yes, it should on the condition that the NFC shield mentioned here supports the NFC tech that the phone would emulate. Check this out: http://developer.android.com/reference/android/nfc/tech/package-summary.html

    0
    JeremyPougnet

    Hello, I'm really interested on this little project. But I have one question. I was wondering if this will also work on windows 8, or if the code you provide is only for Macs. Thank you.

    0
    shasan11
    shasan11

    6 years ago on Introduction

    can i do this using a arduino mega and elecfreaks NFC shield?
    thanks in advance

    0
    The Electrodog Show
    The Electrodog Show

    Reply 6 years ago on Introduction

    I think a mega should work you would just have to switch the pins around. I don't know about that shield. The code is for the Adafruit one.