Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Save password to password manager

24 views
Skip to first unread message

Marc Patermann

unread,
Apr 18, 2013, 9:28:33 AM4/18/13
to dev-ext...@lists.mozilla.org
Hi,

I'm dealing with an extension build by a third party for us. This is
still working in Thunderbird 2.0.

We are about to update to ESR 17 now.
Most of the extension sill works, which is fine.

There is a "Change Password" function, which updates the users password
in LDAP and changes in the password manager.
Changing the pw in LDAP still works too (This is done via an HTTP
gateway; it think these are the "ajax" code line for, right?).
But the extension seems to hang while trying to update the pw in the pw
manager.

Here is the code for saving the new password:

saveData: function(){
// password validation skipped
// [...]
//
var ajax = new OFDhttp(OFDtools.getPref('extensions.ofd.gateway'));
ajax.setVar('do','newpass');
ajax.setVar('newpass',p1);
var serv =
OFDtools.getAccountServer(document.getElementById('ofd-mailaccounts'));
ajax.setVar('user',serv.realUsername);
ajax.setVar('pass',serv.password);
ajax.setVar('host',serv.realHostName);
ajax.onCompletion = function() {
ofdpassword.handleSave(this,serv) };

ajax.runAJAX();
return false;
}
handleSave: function(ajax,serv){
var newpass = ajax.data;

// save back to password manager
var pm = OFDtools.getService('@mozilla.org/passwordmanager;1',
'nsIPasswordManager');
// imap

pm.addUser(serv.type+'://'+encodeURIComponent(serv.username)+'@'+
encodeURIComponent(serv.hostName),
serv.realUsername, newpass);
// smtp
pm.addUser('smtp://'+encodeURIComponent(serv.realUsername)+'@'+
encodeURIComponent(serv.hostName),
serv.realUsername, newpass);

OFDtools.alert('Your Password has changed','Ok');

}

Is there an easy way to change the code to get it working again?
Can someone point me in the right direction?


Marc

Nicolas Lascombes

unread,
Apr 18, 2013, 9:39:58 AM4/18/13
to Marc Patermann, dev-ext...@lists.mozilla.org
Hello,

since Thunderbird 3.0 you need to use nsILoginManager instead of
nsIPasswordManager

https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsILoginManager/Using_nsILoginManager

On Thu, Apr 18, 2013 at 3:28 PM, Marc Patermann <
hans....@ofd-z.niedersachsen.de> wrote:

> Hi,
>
> I'm dealing with an extension build by a third party for us. This is still
> working in Thunderbird 2.0.
>
> We are about to update to ESR 17 now.
> Most of the extension sill works, which is fine.
>
> There is a "Change Password" function, which updates the users password in
> LDAP and changes in the password manager.
> Changing the pw in LDAP still works too (This is done via an HTTP gateway;
> it think these are the "ajax" code line for, right?).
> But the extension seems to hang while trying to update the pw in the pw
> manager.
>
> Here is the code for saving the new password:
>
> saveData: function(){
> // password validation skipped
> // [...]
> //
> var ajax = new OFDhttp(OFDtools.getPref('**
> extensions.ofd.gateway'));
> ajax.setVar('do','newpass');
> ajax.setVar('newpass',p1);
> var serv = OFDtools.getAccountServer(**
> document.getElementById('ofd-**mailaccounts'));
> ajax.setVar('user',serv.**realUsername);
> ajax.setVar('pass',serv.**password);
> ajax.setVar('host',serv.**realHostName);
> ajax.onCompletion = function() { ofdpassword.handleSave(this,**serv)
> };
>
> ajax.runAJAX();
> return false;
> }
> handleSave: function(ajax,serv){
> var newpass = ajax.data;
>
> // save back to password manager
> var pm = OFDtools.getService('@mozilla.**org/passwordmanager;1<http://mozilla.org/passwordmanager;1>
> ',
> 'nsIPasswordManager');
> // imap
>
> pm.addUser(serv.type+'://'+**encodeURIComponent(serv.**username)+'@'+
> encodeURIComponent(serv.**hostName),
> serv.realUsername, newpass);
> // smtp
> pm.addUser('smtp://'+**encodeURIComponent(serv.**
> realUsername)+'@'+
> encodeURIComponent(serv.**hostName),
> serv.realUsername, newpass);
>
> OFDtools.alert('Your Password has changed','Ok');
>
> }
>
> Is there an easy way to change the code to get it working again?
> Can someone point me in the right direction?
>
>
> Marc
> ______________________________**_________________
> dev-extensions mailing list
> dev-ext...@lists.mozilla.**org <dev-ext...@lists.mozilla.org>
> https://lists.mozilla.org/**listinfo/dev-extensions<https://lists.mozilla.org/listinfo/dev-extensions>
>

Marc Patermann

unread,
Apr 19, 2013, 7:32:32 AM4/19/13
to Nicolas Lascombes, dev-ext...@lists.mozilla.org
Nicolas Lascombes schrieb (18.04.2013 15:39 Uhr):

> since Thunderbird 3.0 you need to use nsILoginManager instead
> of nsIPasswordManager
>
> https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsILoginManager/Using_nsILoginManager
Thanks a lot!

I addition to your link I found this post about how to use it in
Thunderbird:

https://mail.mozilla.org/pipermail/tb-enterprise/2012-November/000670.html

> On Thu, Apr 18, 2013 at 3:28 PM, Marc Patermann
> <hans....@ofd-z.niedersachsen.de
> <mailto:hans....@ofd-z.niedersachsen.de>> wrote:
>
> Hi,
>
> I'm dealing with an extension build by a third party for us. This is
> still working in Thunderbird 2.0.
>
> We are about to update to ESR 17 now.
> Most of the extension sill works, which is fine.
>
> There is a "Change Password" function, which updates the users
> password in LDAP and changes in the password manager.
> Changing the pw in LDAP still works too (This is done via an HTTP
> gateway; it think these are the "ajax" code line for, right?).
> But the extension seems to hang while trying to update the pw in the
> pw manager.
>
> Here is the code for saving the new password:
>
> saveData: function(){
> // password validation skipped
> // [...]
> //
> var ajax = new
> OFDhttp(OFDtools.getPref('__extensions.ofd.gateway'));
> ajax.setVar('do','newpass');
> ajax.setVar('newpass',p1);
> var serv =
> OFDtools.getAccountServer(__document.getElementById('ofd-__mailaccounts'));
> ajax.setVar('user',serv.__realUsername);
> ajax.setVar('pass',serv.__password);
> ajax.setVar('host',serv.__realHostName);
> ajax.onCompletion = function() {
> ofdpassword.handleSave(this,__serv) };
>
> ajax.runAJAX();
> return false;
> }
> handleSave: function(ajax,serv){
> var newpass = ajax.data;
>
> // save back to password manager
> var pm =
> OFDtools.getService('@mozilla.__org/passwordmanager;1
> <http://mozilla.org/passwordmanager;1>',
> 'nsIPasswordManager');
> // imap
>
> pm.addUser(serv.type+'://'+__encodeURIComponent(serv.__username)+'@'+
> encodeURIComponent(serv.__hostName),
> serv.realUsername, newpass);
> // smtp
>
> pm.addUser('smtp://'+__encodeURIComponent(serv.__realUsername)+'@'+
> encodeURIComponent(serv.__hostName),
> serv.realUsername, newpass);
>
> OFDtools.alert('Your Password has changed','Ok');
>
> }
>
> Is there an easy way to change the code to get it working again?
> Can someone point me in the right direction?
I changed my code to this:

handleSave: function(ajax,serv){
var newpass = ajax.data;

var nsLoginInfo = new Components.Constructor(
"@mozilla.org/login-manager/loginInfo;1",
Components.interfaces.nsILoginInfo,
"init"
);

// imap
//pm.addUser(serv.type+'://'+encodeURIComponent(serv.username)+'@'+
// encodeURIComponent(serv.hostName), serv.realUsername, newpass);
var loginInfo_IMAP = new nsLoginInfo("imap://" + serv.hostName, "", "",
serv.realUsername, "", newpass);
loginManager.addLogin(loginInfo_IMAP);

// smtp
//pm.addUser('smtp://'+encodeURIComponent(serv.realUsername)+'@'+
// encodeURIComponent(serv.hostName), serv.realUsername, newpass);
var loginInfo_SMTP = new nsLoginInfo("smtp://" + serv.hostName, "", "",
serv.realUsername, "", newpass);
loginManager.addLogin(loginInfo_SMTP);

OFDtools.alert('Your password has changed','Ok');

}

But it still does not work. I still have the "spinning wheel" waiting
for something to end, which does not happen.
The password is sill updated in LDAP though.

Because of the difficulties in updating entries in the password manager
mentioned in the documentation, I tried with an an empty password
manger. Without success.
Something still seams to be wrong here.



Marc

Nicolas Lascombes

unread,
Apr 19, 2013, 8:53:55 AM4/19/13
to Marc Patermann, dev-ext...@lists.mozilla.org
Try to surround your code with try catch to get errors messages.

try {
your code;
} catch (ex) {
OFDtools.alert("error", ex);
}

On Fri, Apr 19, 2013 at 1:32 PM, Marc Patermann <
hans....@ofd-z.niedersachsen.de> wrote:

> Nicolas Lascombes schrieb (18.04.2013 15:39 Uhr):
>
>
> since Thunderbird 3.0 you need to use nsILoginManager instead of
>> nsIPasswordManager
>>
>> https://developer.mozilla.org/**en-US/docs/XPCOM_Interface_**
>> Reference/nsILoginManager/**Using_nsILoginManager<https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsILoginManager/Using_nsILoginManager>
>>
> Thanks a lot!
>
> I addition to your link I found this post about how to use it in
> Thunderbird:
>
> https://mail.mozilla.org/**pipermail/tb-enterprise/2012-**
> November/000670.html<https://mail.mozilla.org/pipermail/tb-enterprise/2012-November/000670.html>
>
> On Thu, Apr 18, 2013 at 3:28 PM, Marc Patermann <hans.moser@ofd-z.**
>> niedersachsen.de <hans....@ofd-z.niedersachsen.de> <mailto:
>> hans.moser@ofd-z.**niedersachsen.de <hans....@ofd-z.niedersachsen.de>>>
>> wrote:
>>
>> Hi,
>>
>> I'm dealing with an extension build by a third party for us. This is
>> still working in Thunderbird 2.0.
>>
>> We are about to update to ESR 17 now.
>> Most of the extension sill works, which is fine.
>>
>> There is a "Change Password" function, which updates the users
>> password in LDAP and changes in the password manager.
>> Changing the pw in LDAP still works too (This is done via an HTTP
>> gateway; it think these are the "ajax" code line for, right?).
>> But the extension seems to hang while trying to update the pw in the
>> pw manager.
>>
>> Here is the code for saving the new password:
>>
>> saveData: function(){
>> // password validation skipped
>> // [...]
>> //
>> var ajax = new
>> OFDhttp(OFDtools.getPref('__**extensions.ofd.gateway'));
>>
>> ajax.setVar('do','newpass');
>> ajax.setVar('newpass',p1);
>> var serv =
>> OFDtools.getAccountServer(__**document.getElementById('ofd-_**
>> _mailaccounts'));
>> ajax.setVar('user',serv.__**realUsername);
>> ajax.setVar('pass',serv.__**password);
>> ajax.setVar('host',serv.__**realHostName);
>> ajax.onCompletion = function() {
>> ofdpassword.handleSave(this,__**serv) };
>>
>>
>> ajax.runAJAX();
>> return false;
>> }
>> handleSave: function(ajax,serv){
>> var newpass = ajax.data;
>>
>> // save back to password manager
>> var pm =
>> OFDtools.getService('@mozilla.**__org/passwordmanager;1
>> <http://mozilla.org/**passwordmanager;1<http://mozilla.org/passwordmanager;1>
>> >',
>> 'nsIPasswordManager');
>> // imap
>>
>> pm.addUser(serv.type+'://'+__**encodeURIComponent(serv.__**
>> username)+'@'+
>> encodeURIComponent(serv.__**hostName),
>> serv.realUsername, newpass);
>> // smtp
>> pm.addUser('smtp://'+__**encodeURIComponent(serv.__**
>> realUsername)+'@'+
>> encodeURIComponent(serv.__**hostName),
>>
>> serv.realUsername, newpass);
>>
>> OFDtools.alert('Your Password has changed','Ok');
>>
>> }
>>
>> Is there an easy way to change the code to get it working again?
>> Can someone point me in the right direction?
>>
> I changed my code to this:
>
>
> handleSave: function(ajax,serv){
> var newpass = ajax.data;
>
> var nsLoginInfo = new Components.Constructor(
> "@mozilla.org/login-manager/**loginInfo;1<http://mozilla.org/login-manager/loginInfo;1>
> ",
> Components.interfaces.**nsILoginInfo,
> "init"
> );
>
> // imap
> //pm.addUser(serv.type+'://'+**encodeURIComponent(serv.**username)+'@'+
> // encodeURIComponent(serv.**hostName), serv.realUsername, newpass);
> var loginInfo_IMAP = new nsLoginInfo("imap://" + serv.hostName, "", "",
> serv.realUsername, "", newpass);
> loginManager.addLogin(**loginInfo_IMAP);
>
> // smtp
> //pm.addUser('smtp://'+**encodeURIComponent(serv.**realUsername)+'@'+
> // encodeURIComponent(serv.**hostName), serv.realUsername, newpass);
> var loginInfo_SMTP = new nsLoginInfo("smtp://" + serv.hostName, "", "",
> serv.realUsername, "", newpass);
> loginManager.addLogin(**loginInfo_SMTP);

Marc Patermann

unread,
Apr 19, 2013, 9:54:05 AM4/19/13
to Nicolas Lascombes, dev-ext...@lists.mozilla.org
Nicolas,

Nicolas Lascombes schrieb (19.04.2013 14:53 Uhr):
> Try to surround your code with try catch to get errors messages.
>
> try {
> your code;
> } catch (ex) {
> OFDtools.alert("error", ex);
> }
There have been a few error, I corrected by now. Thanks again!

Error message now is:

errorTypeError: nsLoginInfo.addLogin is not a function

Code is:

handleSave: function(ajax,serv){
var newpass = ajax.data;
try {
var nsLoginInfo = new Components.Constructor(
"@mozilla.org/login-manager/loginInfo;1",
Components.interfaces.nsILoginInfo,
"init"
);

// imap
var loginInfo_IMAP = new nsLoginInfo("imap://" + serv.hostName,
"imap://" + serv.hostName, "", serv.realUsername, newpass, "", "");
nsLoginInfo.addLogin(loginInfo_IMAP);

// smtp
var loginInfo_SMTP = new nsLoginInfo("smtp://" + serv.hostName,
"smtp://" + serv.hostName, "", serv.realUsername, newpass, "", "");
nsLoginInfo.addLogin(loginInfo_SMTP);
} catch (ex) {
OFDtools.alert("error"+ ex,"OK");
}


OFDtools.alert('Your Password has changed','Ok');

}



Marc

Nicolas Lascombes

unread,
Apr 22, 2013, 3:49:51 AM4/22/13
to Marc Patermann, dev-ext...@lists.mozilla.org
Hello,

it's because you are calling the constructor function and not an instance.
loginInfo_IMAP.add()

On Fri, Apr 19, 2013 at 3:54 PM, Marc Patermann <
hans....@ofd-z.niedersachsen.de> wrote:

> Nicolas,
>
> Nicolas Lascombes schrieb (19.04.2013 14:53 Uhr):
>
> > Try to surround your code with try catch to get errors messages.
> >
> > try {
> > your code;
> > } catch (ex) {
> > OFDtools.alert("error", ex);
> > }
> There have been a few error, I corrected by now. Thanks again!
>
> Error message now is:
>
> errorTypeError: nsLoginInfo.addLogin is not a function
>
> Code is:
>
>
> handleSave: function(ajax,serv){
> var newpass = ajax.data;
> try {
>
> var nsLoginInfo = new Components.Constructor(
> "init"
> );
>
> // imap
> var loginInfo_IMAP = new nsLoginInfo("imap://" + serv.hostName, "imap://"
> + serv.hostName, "", serv.realUsername, newpass, "", "");
> nsLoginInfo.addLogin(**loginInfo_IMAP);
>
> // smtp
> var loginInfo_SMTP = new nsLoginInfo("smtp://" + serv.hostName, "smtp://"
> + serv.hostName, "", serv.realUsername, newpass, "", "");
> nsLoginInfo.addLogin(**loginInfo_SMTP);

Marc Patermann

unread,
Apr 22, 2013, 8:32:58 AM4/22/13
to Nicolas Lascombes, dev-ext...@lists.mozilla.org
Hi,

Nicolas Lascombes schrieb (22.04.2013 09:49 Uhr):

> it's because you are calling the constructor function and not an instance.
> loginInfo_IMAP.add()
The problem was, I had mixed up Components.interfaces.nsILoginManager
and Components.interfaces.nsILoginInfo and had only one.

This is the working code (step one; dealing with existing entries later):

handleSave: function(ajax,serv){
var newpass = ajax.data;
try {
var passwordManager =
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");

// imap
var loginInfo_IMAP = new nsLoginInfo("imap://" + serv.hostName, null,
"imap://" + serv.hostName, serv.realUsername, newpass, "", "");
passwordManager.addLogin(loginInfo_IMAP);

// smtp
var loginInfo_SMTP = new nsLoginInfo("smtp://" + serv.hostName, null,
"smtp://" + serv.hostName, serv.realUsername, newpass, "", "");
passwordManager.addLogin(loginInfo_SMTP);

} catch (ex) {
OFDtools.alert("error"+ ex,"OK");
}
OFDtools.alert('You Password has changed','Ok');

}


Thanks everyone for your help!

FYI: To store login in information in Thunderbird's password manager,
you have to set formSubmitURL = null and httprealm = hostname, which is
"protocol:// + servername".


Marc
0 new messages