Primitive password tracking support (bug 435320, r=thunder)

This commit is contained in:
Anant Narayanan 2008-06-30 11:19:07 -07:00
Родитель 7eb4f6a421
Коммит 35b5fc1915
1 изменённых файлов: 45 добавлений и 0 удалений

Просмотреть файл

@ -198,3 +198,48 @@ PasswordStore.prototype = {
};
PasswordStore.prototype.__proto__ = new Store();
function PasswordTracker() {
this._init();
}
PasswordTracker.prototype = {
_logName: "PasswordTracker",
__loginManager : null,
get _loginManager() {
if (!this.__loginManager)
this.__loginManager = Cc["@mozilla.org/login-manager;1"].
getService(Ci.nsILoginManager);
return this.__loginManager;
},
/* We use nsILoginManager's countLogins() method, as it is
* the only method that doesn't require the user to enter
* a master password, but still gives us an idea of how much
* info has changed.
*
* FIXME: This does not track edits of passwords, so we
* artificially add 30 to every score. We should move to
* using the LoginManager shim at some point.
*
* Each addition/removal is worth 15 points.
*/
_loginCount: 0,
get score() {
var count = this._loginManager.countLogins("", "", "");
var score = Math.abs(this._loginCount - count) * 15;
if (score >= 100)
return 100;
else
return score + 30;
},
resetScore: function PasswordTracker_resetScore() {
this._loginCount = this._loginManager.countLogins("", "", "");
},
_init: function PasswordTracker__init() {
this._log = Log4Moz.Service.getLogger("Service." this._logName);
this._loginCount = this._loginManager.countLogins("", "", "");
}
}