Mozilla Add-on development: Accessing LAST USED or LAST CHANGED fields in password manger

喜夏-厌秋 提交于 2019-12-11 10:06:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!