Instructables
Picture of 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. 
 
Remove these adsRemove these ads by Signing Up

Step 1: Parts Needed

Picture of Parts Needed
ID789part_LRG.jpg
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

Picture of 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. 
Andersv2098 months ago

why do you have to change the pin from 2 to 6 ?

The Electrodog Show (author)  Andersv2098 months ago

The NFC shield doesn't talk well with the Arduino Leonardo at pin 2. Pin 6 is the IRQ pin that works on the Leonardo.

i see, but maybe you should tell that in the instructeable ? :) so people with an uno dont do it, and in the code explain what it should be for uno and leonardo ? :)

Doing this using an arduino UNO is an entirely different matter. The Leonardo is able to act as a HID because of its special AVR chip which combines the actual microprocessor and the processor used for serial communication on an UNO or an Mega (or an 2009, if I am not mistaken). If you have an UNO or Mega available, you can see this second microcontroller for USB communication next to the USB poet. It will have something like Mega8U2 or Mega16U2 written on it. Using such Arduinos as a HID is pony possible by flashing a different firmware onto this chip using something called DFU. This involves cutting a jumper on an UNO R1 and will make your arduino inaccessible for programming until you flash the vanilla firmware onto the chip. Speaking from experience, this is kind of annoying.
*only
The Electrodog Show (author)  Andersv2098 months ago
(removed by author or community request)

you are welcome :)

shasan114 months ago

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

The Electrodog Show (author)  shasan114 months ago
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.
nfctags5 months ago

Wow!! It's so cool and interesting.see http://www.nfcbusinesscards.us/nfc-tags/

stopspazzing6 months ago

Hi, thanks for this great idea. HOWEVER, this does NOT UNLOCK your computer, it enters your password. The title is misleading. Please update your title to something like "NFC Computer Password Autotyper".

rypi7 months ago

you could add this piece of code so that you don't have to even press the enter key

Keyboard.write(KEY_RETURN);

Treknology7 months ago

Very nice little project that also means you can have ludicrously long passwords to keep unwanted siblings out of your system.

Really cool stuff! But a couple recommendations.

I would recommend using an auxillary program (perhaps a web service) to store and manage what passwords map to which cards. Just have a simple interface where your device contacts a web service running on your network somewhere, if the card is a new card, it will register it in the database along with a timestamp so you can go in and assign a username and password to it. The password would be encrypted of course. Then find a way to either have the web app authenticate you and let you in, or come up with another way to input the password.

It's just that hard coding anything into a program..especially something sensitive like a password, is just a bad idea. And from a design perspective, a violation of DRY among other things.

All that being said though...this is a clever idea, and I would love to see you develop it further. If I can be of any assistance, let me know. I can help you write the web service.

Thanks for the idea! You are right, this project is probably not too secure. I posted this as more as a concept. For a business computer, this probably isn't the best idea! :-)

I have been meaning to do an instructable about the smart power strip I have been working on using Arduino and a Web Application that controls it. The prototype is done, just been too lazy to finish.
Also, I would strongly recommend looking at the algorithms for authentication and encryption built into some NFC tags for added security.
barathi7 months ago

Hey, i had a question. I have a Nexus 5 with built in NFC, do you know if it's possible to use that NFC chip? If so, how?

Thanks in advance and thanks for this guide :)

The Electrodog Show (author)  barathi7 months ago

I don't believe it is possible to use a phone to interact with the NFC Shield. The shield and your phone are only meant to read and write to cards, not to be one itself. You could take apart the card and put the small NFC circuit in your phone case;-)

thats strange, the nfc on my nexus 7 communicates with other devices via nfc. its used to share things, such as apps and webpages.
I am afraid this will probably not work since your phone has got an NFC chip which transmits in an "active mode", as opposed to the passive Mifare cards used in this project. I can assure you that your phone could not interface with this board using the code in the instructable, as that would require the NFC chip in your Nexus to be able to emulate the technology in the Mifare card, which requires special hardware and can't be done in software. It might be possible to program the arduino to interface with an active target and write an Android app for interfacing the board. This will, however, be quite hard to do.
You might be interested in this video from Google IO 2011 (it's annual developer conference), which is quite long and technical, but very helpful, to get a comprehensive overview of this rather complex matter: Google I/O 2011: How to NFC: http://youtu.be/49L7z3rxz4Q
cmori7 months ago

Nice Job.

It would be nead to have a separate authentication process instead of emulating a password.

See here

http://en.wikipedia.org/wiki/Graphical_identification_and_authentication

ransomhall7 months ago

So does the keyboard emulator allow for special chars typed simultaneously? Could you extend this to unlock the computer with ctrl+alt+del enter, then the password?

Syx ransomhall7 months ago

There's no "ascii" character for Ctrl, Alt, Delete but you can do something like

Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_DELETE);
delay(100);
Keyboard.releaseAll();

//Write password here

Keyboard.write(KEY_RETURN);

That would work :)

The Electrodog Show (author)  ransomhall7 months ago

You could totally do that! Just have the keyboard.write statements press ascii number for the key you want to press. View all of the Ascii numbers here: http://www.asciitable.com/

colinj7 months ago
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?
The Electrodog Show (author)  colinj7 months ago

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 :-)

hbsbh817 months ago

Could i use my mobile to unlock it?

Or is that like holding a reader to a reader?

Would be kind of cool to unlock the computer just by placeing your android on the table.

The Electrodog Show (author)  hbsbh817 months ago

I haven't had any luck getting my phone to work, I think its like holding a reader to a reader.

webbhost7 months ago

Looking at google, I'm assuming there is nothing to stop you writing:

Keyboard.write(KEY_RETURN);

after your password to cut out pressing enter? Make it more automated like!

The Electrodog Show (author)  webbhost7 months ago

That's a great suggestion! Sometimes I don't need the enter key to be pressed when entering a password. For that reason I didn't do that.

going to assume you use it for more than just your login? - e.g. website logins or signup pages which require pass but not ENTER as it would submit form too quickly?

I guess theres nothing to stop you using a second NFC key through so you can have 1 with enter and 1 without!

I do love this idea through, imght favourite it so I can give it a whirl when I have some spare time!

Out of interest how did you manage to make your box? 3D printers are extremely expensive and I can't imagine you went to that length?
The Electrodog Show (author)  webbhost7 months ago

Let me know if you do make it! I did use my Printrbot to print a case for the project. You could either use an online print service or take it to a local hacker space (if you live in a big city).

webbhost webbhost7 months ago

Just a random thought but how does this cope when first switching on your computer? Does the NFC service start before you've even logged in initially - or does it only work once you've logged in and you "lock" your computer?

The Electrodog Show (author)  webbhost7 months ago

This works all the time after the Arduino starts up (about 5 seconds.)