Well, a module called PAM (Pluggable Authentication module) can be customized to achieve your need. A beautiful article is available on linuxconfig describing this in detail.
The steps are:
Install PAM
$ sudo apt-get install pamusb-tools libpam-usb
Add USB device to PAM config