|
1 // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 var gRemovePasswordDialog = { |
|
8 _token : null, |
|
9 _bundle : null, |
|
10 _prompt : null, |
|
11 _okButton : null, |
|
12 _password : null, |
|
13 init: function () |
|
14 { |
|
15 this._prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] |
|
16 .getService(Components.interfaces.nsIPromptService); |
|
17 this._bundle = document.getElementById("bundlePreferences"); |
|
18 |
|
19 this._okButton = document.documentElement.getButton("accept"); |
|
20 this._okButton.label = this._bundle.getString("pw_remove_button"); |
|
21 |
|
22 this._password = document.getElementById("password"); |
|
23 |
|
24 var pk11db = Components.classes["@mozilla.org/security/pk11tokendb;1"] |
|
25 .getService(Components.interfaces.nsIPK11TokenDB); |
|
26 this._token = pk11db.getInternalKeyToken(); |
|
27 |
|
28 // Initialize the enabled state of the Remove button by checking the |
|
29 // initial value of the password ("" should be incorrect). |
|
30 this.validateInput(); |
|
31 }, |
|
32 |
|
33 validateInput: function () |
|
34 { |
|
35 this._okButton.disabled = !this._token.checkPassword(this._password.value); |
|
36 }, |
|
37 |
|
38 removePassword: function () |
|
39 { |
|
40 if (this._token.checkPassword(this._password.value)) { |
|
41 this._token.changePassword(this._password.value, ""); |
|
42 this._prompt.alert(window, |
|
43 this._bundle.getString("pw_change_success_title"), |
|
44 this._bundle.getString("pw_erased_ok") |
|
45 + " " + this._bundle.getString("pw_empty_warning")); |
|
46 } |
|
47 else { |
|
48 this._password.value = ""; |
|
49 this._password.focus(); |
|
50 this._prompt.alert(window, |
|
51 this._bundle.getString("pw_change_failed_title"), |
|
52 this._bundle.getString("incorrect_pw")); |
|
53 } |
|
54 }, |
|
55 }; |
|
56 |