firefox sdk插件中的主密码验证

时间:2016-09-28 14:11:28

标签: javascript firefox-addon firefox-addon-sdk

要求用户在firefox sdk插件中设置主密码的命令是什么。如果用户不使用主密码,那么我需要设置用户设置主密码。怎么做。我应该使用哪个令牌功能来弹出主密码设置块。

提前致谢

1 个答案:

答案 0 :(得分:0)

var me = Services.wm.getMostRecentWindow(null);
var tokenDB = Cc['@mozilla.org/security/pk11tokendb;1'].getService(Ci.nsIPK11TokenDB);
var master_password = tokenDB.getInternalKeyToken();

var master_password_authenticated;
try {
    master_password_authenticated = Components.isSuccessCode(token.login(false)); //login argument is false meaning that if the user had previously entered their master password it will not prompt them now AND if they had not entered it before and it is still valid for the session it will NOT prompt. IF you set it to true then regardless if the user entered it in before or not it will force them to enter it again
} catch (ex) {
    master_password_authenticated = false;
}

me.alert('master passsword pass? = ' + master_password_authenticated);

这将告诉您"如果用户拥有主密码,他们是否已获得授权"。