Password Manager: Difference between revisions

From MozillaZine Knowledge Base
Jump to navigationJump to search
(safer version of the print code)
(save passwords as JSON format)
Line 31: Line 31:


You can also use the [https://addons.mozilla.org/en-US/firefox/addon/2848 Password Exporter extension] to back up your passwords.
You can also use the [https://addons.mozilla.org/en-US/firefox/addon/2848 Password Exporter extension] to back up your passwords.
You can also create a backup in JSON format with the code shown below. Copy and paste the code in the Code field in the Tools > Error Console and click the Evaluate button<pre>
(function(){
var Cc = Components.classes;
var Ci = Components.interfaces;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var tokendb = Cc["@mozilla.org/security/pk11tokendb;1"]
                .createInstance(Ci.nsIPK11TokenDB);
var token = tokendb.getInternalKeyToken();
try { token.login(true);} catch (e) { }
if (token.isLoggedIn()) {
var passwordmanager = Cc["@mozilla.org/login-manager;1"]
                        .getService(Ci.nsILoginManager);
var signons = passwordmanager.getAllLogins({});
for (i=0;i<signons.length;i++) {
  try {
  var host = signons[i].hostname;
  var realm = signons[i].httpRealm;
  var user = signons[i].username;
  var userf = signons[i].usernameField;
  var password = signons[i].password;
  var passwordf = signons[i].passwordField;
  var submiturl = signons[i].formSubmitURL;
  } catch(e) {}
}
var json =Cc["@mozilla.org/dom/json;1"]
  .createInstance(Ci.nsIJSON)
  .encode(signons);
var fp=Cc["@mozilla.org/filepicker;1"]
          .createInstance(Components.interfaces.nsIFilePicker);
fp.init(window,"",Ci.nsIFilePicker.modeSave);
fp.defaultString="signons.json";
fp.show();
var filoutputStream=Cc["@mozilla.org/network/file-output-stream;1"]
                      .createInstance(Ci.nsIFileOutputStream);
filoutputStream.init(fp.file,0x04|0x08,420,0);
filoutputStream.write(json,json.length);
filoutputStream.close();
}
})()
</pre>


== Printing passwords ==
== Printing passwords ==
Line 36: Line 86:


This is the Firefox 3 version of the code from the [http://edmullen.net/Mozilla/display_moz_passwords.html edmullen's site]. You can find the complete file with the Firefox 3 code on: [http://the-edmeister.com/firefox_info/Firefox_Passwords_Info.html the-edmeister's Firefox Informational Website].
This is the Firefox 3 version of the code from the [http://edmullen.net/Mozilla/display_moz_passwords.html edmullen's site]. You can find the complete file with the Firefox 3 code on: [http://the-edmeister.com/firefox_info/Firefox_Passwords_Info.html the-edmeister's Firefox Informational Website].
The version posted below will run in the Tools > Error Console (paste the code in the Code field and click Evaluate) <pre>
The version shown below will run in the Tools > Error Console (paste the code in the Code field and click the Evaluate button) <pre>
(function(){
(function(){
function twodigits(string) {return (string.length < 2) ? "0" + string : string ;}
function twodigits(string) {return (string.length < 2) ? "0" + string : string ;}

Revision as of 13:59, 24 May 2009

This article was written for Firefox but may also apply to Mozilla Suite/SeaMonkey and Thunderbird, although menu sequences may differ.

Firefox includes a feature that allows you to save passwords. If you enter a password in a web form and you do not see a dialog asking you if you want Firefox to remember the password, make sure that "Remember passwords for sites" is enabled in "Tools -> Options -> Security / Passwords.

You can also choose to use a Master password to protect your passwords, which is highly recommended if you share your computer. See the linked article for details.

Using the Password Manager

You access the Password Manager from the Firefox menu via "Tools -> Options -> Security / Passwords".

  • Firefox 3: Click the "Saved Passwords" button to open the "Saved Passwords" window.
  • Firefox 2: Click the "Show Passwords" button to open the "Remember Passwords" window.

The "Saved Passwords" window (Firefox 3) or "Remember Passwords" window (Firefox 2) lists the web sites and user names for your stored passwords and includes a "Show Passwords" button that lets you view your stored passwords.

If you use a Master password then Firefox has access to the passwords as long as you are logged in to the Software Security Device ("Tools > Options > Advanced > Encryption: Certificates: Security Devices: Software Security Device"). See the Master password article for details.

Deleting passwords

To delete stored passwords for web sites and user names listed in the Password Manager, open the "Saved Passwords" or "Remember Passwords" window (see above). Highlight (select) the items that you want to delete and click the "Remove" button (or press the Delete key). Warning: Make sure you do not click the "Remove All" button, as that will remove all the passwords, without asking for confirmation in Firefox 2 and below.

Exceptions

The Exceptions button in "Tools -> Options -> Security / Passwords" opens a window ("Exceptions - Saved Passwords" in Firefox 3 or "Don't Remember Passwords" in Firefox 2) that lists the web domains from which you chose never to store passwords. If you later decide that you do want to store a password from a site on the Exceptions list, you will need to remove that entry. That is done in the same way you would delete a password, by highlighting the entry and clicking the "Remove" button (or pressing the Delete key).

Troubleshooting

If you do not see any passwords in the Password Manager window (Show Passwords) then your passwords are probably lost. If you still see encrypted names and passwords in the file signons3.txt (signons2.txt in Firefox 2.0.0.x) then a possible cause is a wrong or corrupted key3.db file. In Firefox 3.0.2 and 3.0.3 it can also be a problem with the encoding [1][2][3]. If you have updated from Firefox 2 to Firefox 3 and you haven't changed the Master Password then you can try to copy or rename a still existing signons2.txt to signons3.txt to see if that works. If you can't add new passwords but still see your old passwords in the Password Manager window then use the Password Exporter extension to export your current passwords and delete key3.db and delete or rename all signons#.txt files (e.g. signons3.txt and signons2.txt) in the Profile folder. You can also do that if you lost your Master password and the suggestions in the Master password article didn't work. You need to set a new Master password after deleting the file key3.db.

Backing up and restoring passwords

Firefox stores your password data in two files: key3.db (Master Password / Encryption key) and a "signons" file (encrypted names and passwords). You can back up your passwords by making a copy of both "Key3.db" and the "signons" file for your Firefox version. Firefox 2 uses signons2.txt, Firefox 3.0.x uses signons3.txt, and Firefox 3.1, including current Beta and nightly builds, uses signons.sqlite. [4] See Profile folder - Firefox and Profile backup for additional information.

You can also use the Password Exporter extension to back up your passwords.

You can also create a backup in JSON format with the code shown below. Copy and paste the code in the Code field in the Tools > Error Console and click the Evaluate button

(function(){
var Cc = Components.classes;
var Ci = Components.interfaces;

netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var tokendb = Cc["@mozilla.org/security/pk11tokendb;1"]
                .createInstance(Ci.nsIPK11TokenDB);
var token = tokendb.getInternalKeyToken();

try { token.login(true);} catch (e) { }

if (token.isLoggedIn()) {
 var passwordmanager = Cc["@mozilla.org/login-manager;1"]
                         .getService(Ci.nsILoginManager);
 var signons = passwordmanager.getAllLogins({});

 for (i=0;i<signons.length;i++) {
  try {
   var host = signons[i].hostname;
   var realm = signons[i].httpRealm;
   var user = signons[i].username;
   var userf = signons[i].usernameField;
   var password = signons[i].password;
   var passwordf = signons[i].passwordField;
   var submiturl = signons[i].formSubmitURL;
   } catch(e) {}
 }

 var json =Cc["@mozilla.org/dom/json;1"]
  .createInstance(Ci.nsIJSON)
  .encode(signons);

 var fp=Cc["@mozilla.org/filepicker;1"]
          .createInstance(Components.interfaces.nsIFilePicker);

 fp.init(window,"",Ci.nsIFilePicker.modeSave);
 fp.defaultString="signons.json";
 fp.show();

 var filoutputStream=Cc["@mozilla.org/network/file-output-stream;1"]
                       .createInstance(Ci.nsIFileOutputStream);

 filoutputStream.init(fp.file,0x04|0x08,420,0);
 filoutputStream.write(json,json.length);
 filoutputStream.close();
}
})()

Printing passwords

If you want a printed copy of the password then look at this forum thread and also read this web page (scroll down to #4).

This is the Firefox 3 version of the code from the edmullen's site. You can find the complete file with the Firefox 3 code on: the-edmeister's Firefox Informational Website.

The version shown below will run in the Tools > Error Console (paste the code in the Code field and click the Evaluate button)

(function(){
function twodigits(string) {return (string.length < 2) ? "0" + string : string ;}
function fourdigits(number){return (number < 1000) ? number + 1900 : number;}

var now = new Date();
var hours = twodigits(now.getHours() + "") ;
var minutes = twodigits(now.getMinutes() + "") ;
var seconds = twodigits(now.getSeconds() + "") ;

var timeValue = " | At  " + hours + ":" + minutes + ":" + seconds;
var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

var today =  "On " + days[now.getDay()] + ", " + date + " " + months[now.getMonth()] + " " +    (fourdigits(now.getYear())) + timeValue ;

var Cc = Components.classes;
var Ci = Components.interfaces;

netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

var tokendb = Cc["@mozilla.org/security/pk11tokendb;1"]
                .createInstance(Ci.nsIPK11TokenDB);
var token = tokendb.getInternalKeyToken();

try { token.login(true);} catch (e) {}

if (token.isLoggedIn()) {
 var passwordmanager = Cc["@mozilla.org/login-manager;1"]
                       .getService(Ci.nsILoginManager);
 var names="",signons = passwordmanager.getAllLogins({});

 for (i=0;i<signons.length;i++) {
  try {
   var host = signons[i].hostname;
   var realm = signons[i].httpRealm;
   var user = signons[i].username;
   var userf = signons[i].usernameField;
   var password = signons[i].password;
   var passwordf = signons[i].passwordField;
   var submiturl = signons[i].formSubmitURL;
   if (user == ""){ user = "<br>"; }
   names+="  <tr>\n    <td> " + host + " </td>\n    <td> " + user + " </td>\n    <td> " + password + "  </td>\n    <td> " + submiturl + " </td>\n  </tr>\n";
   } catch(e) {}
 }

 void(window.open('data:text/html,
<html><head>
<meta http-equiv=content-type" content="text/html; charset=ISO-8859-1">

<title>Exported Mozilla Passwords</title>
<style type="text/css">
 td {
  font-family: "Trebuchet MS", Arial, Helvetica, Geneva, Verdana, Sans-Serif;
  font-size: 85%;
  padding: 1px 2px 1px 2px;
}
</style>
</head><body style="margin: 1em 3em; background-color: rgb(255, 221, 221);">
<b>MOZILLA PASSWORD INFORMATION</b>
<p>Produced by <i>Pasting Code in the "Tools > Error Console: Code field"</i> (by "ernie" - Andrew Poth - Ed Mullen - adopted by dickvl@kb.mozillazine.org to run in the Error Console)<br>'+today+
'</p><p>
<table style="empty-cells: show; background-color: rgb(221, 255, 221);" border="1" cellspacing="0">
<tbody><tr style="background-color: rgb(204, 204, 255);">
<td>
<b>Host</b>
</td>
<td>
<b>User name</b>
</td>
<td>
<b>Password</b>
</td>
<td>
<b>Submit URL</b>
</td>
</tr>'+names+'</tbody></table>
</p></body></html>',"","menubar=yes,resizable=yes,scrollbars=yes,width=1000,height:600"));
}
})();

See also

External links