Closed Bug 1676873 Opened 5 years ago Closed 5 years ago

nsILoginManager is not storing passwords

Categories

(Thunderbird :: Account Manager, defect)

defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: it_support, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36

Steps to reproduce:

Hi,
i have a JS script (to be executed in the Error Console) that creates accounts/identities automatically. It also tries to store the password in the password manager, but this part doesn't work.
Snippet:

      var hostname="mymailserver.com";
      var nsILoginManager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
      var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",Components.interfaces.nsILoginInfo,"init");

// save password	
var loginInfo = new nsLoginInfo("smtp://" + hostname,null,"smtp://" + hostname,username,password,'','');
nsILoginManager.addLogin(loginInfo); // <== ineffective

Actual results:

Thunderbird keeps prompting for pwd at startup.

Expected results:

Maybe the problem is in the last 2 empty arguments to the nsLoginInfo constructor? ( should be the username and pwd form field names).
I have tried inspecting an account created by hand i already had, where the password is stored correctly.
It appears the form field names for that account are empty, so i thought they are just ignored by Thunderbird ( maybe they are important for Firefox only? )
Here is how i figured it out:

   var logins = nsILoginManager.getAllLogins();
  // the first element is about an existing account i have, with password stored
  console.log("usernameField :"+logins[0].usernameField); // prints ""
  console.log("pwd field:"+logins[0].passwordField); // prints ""

Let me know what i am missing thx!

Sorry bugzilla is not developer support forum.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → INVALID

Solved.
I was saving only the password for the SMTP credentials, but not for the incoming server credentials.
The solution was to add these lines:

loginInfo = new nsLoginInfo(incomingServer.localStoreType + "://" + hostname,null,incomingServer.localStoreType + "://" + 
hostname,username,password,'','');
nsILoginManager.addLogin(loginInfo);
You need to log in before you can comment on or make changes to this bug.