问题
My add-on needs to access stored credentials. In this I want to get the credentials that was changed or used recently. I see that I have LAST USED and LAST CHANGED fields but how do I access those fields in my javascript?
I searched and also tried ( https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/passwords ) but I couldn't get anything.
回答1:
This is how to get a list of all the currently stored login informations:
var lm = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
var arrOfLogins = lm.getAllLogins();
var numberOfLogins = arrOfLogins.length;
console.info('arrOfLogins:', arrOfLogins);
var myObjs = [];
for (var i=0; i<numberOfLogins; i++) {
var pushObj = {};
pushObj.username = arrOfLogins[i].username;
pushObj.password = arrOfLogins[i].password;
pushObj.hostname = arrOfLogins[i].hostname;
arrOfLogins[i].QueryInterface(Ci.nsILoginMetaInfo);
pushObj.lastUsed = new Date(arrOfLogins[i].timeLastUsed);
pushObj.lastChanged = new Date(arrOfLogins[i].timePasswordChanged);
myObjs.push(pushObj);
}
console.info('myObjs:', myObjs);
If the user has a master password, you have to prompt them to fill it out, otherwise the above iwll fail im pretty sure.
来源:https://stackoverflow.com/questions/32170383/mozilla-add-on-development-accessing-last-used-or-last-changed-fields-in-passwo