Factory reset upon unlocking For security reasons, I want to be able to specify two lock passwords (or patterns) as follows :

One for normal unlocking the device. 

Another one if entered, the device will factory reset itself (and maybe format the SD)

I want this to happen from the main Android lock screen, but with two passwords.
I do not know of any application that does what you request. Maybe "After Unlock" has a feature like that. 

What I would do is make an Android application that is fired after unlocking the phone. The application would request a new password and if it is entered correctly do the factory reset and format the SD if needed. 

Check this project for an example of how this could be done: myLock