Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

nsILoginManager

Used to interface with the built-in Password Manager
1.0
28
Introduced
Gecko 1.9
Inherits from: nsISupports Last changed in Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)

Replaces nsIPasswordManager which was used in older versions of Gecko.

Implemented by: @mozilla.org/login-manager;1. To create an instance, use:

var loginManager = Components.classes["@mozilla.org/login-manager;1"]
                   .getService(Components.interfaces.nsILoginManager);

Method overview

void addLogin(in nsILoginInfo aLogin);
nsIAutoCompleteResult autoCompleteSearch(in AString aSearchString, in nsIAutoCompleteResult aPreviousResult, in nsIDOMHTMLInputElement aElement);
unsigned long countLogins(in AString aHostname, in AString aActionURL, in AString aHttpRealm);
boolean fillForm(in nsIDOMHTMLFormElement aForm);
void findLogins(out unsigned long count, in AString aHostname, in AString aActionURL, in AString aHttpRealm, [retval, array, size_is(count)] out nsILoginInfo logins);
void getAllDisabledHosts([optional] out unsigned long count, [retval, array, size_is(count)] out wstring hostnames);
void getAllLogins([optional] out unsigned long count, [retval, array, size_is(count)] out nsILoginInfo logins);
boolean getLoginSavingEnabled(in AString aHost);
void modifyLogin(in nsILoginInfo oldLogin, in nsISupports newLoginData);
void removeAllLogins();
void removeLogin(in nsILoginInfo aLogin);
void searchLogins(out unsigned long count, in nsIPropertyBag matchData, [retval, array, size_is(count)] out nsILoginInfo logins);
void setLoginSavingEnabled(in AString aHost, in boolean isEnabled);

Methods

addLogin()

Stores a new login in the Login Manager.

Note : Default values for the nsILoginMetaInfo properties are created if the specified login doesn't explicitly specify them.

void addLogin(
  in nsILoginInfo aLogin
);
Parameters
aLogin
The login to store.
Exceptions thrown
 
An exception is thrown if the login information is already stored in the Login Manager. To change a login, you have to use modifyLogin().

autoCompleteSearch()

Generates results for a user field autocomplete menu.

Note : This method is provided for use only by the FormFillController, which calls it directly. It should not be used for any other purpose.

nsIAutoCompleteResult autoCompleteSearch(
  in AString aSearchString,
  in nsIAutoCompleteResult aPreviousResult,
  in nsIDOMHTMLInputElement aElement
);
Parameters
aSearchString
Missing Description
aPreviousResult
Missing Description
aElement
Missing Description
Return value

Missing Description

countLogins()

Returns the number of logins matching the specified criteria. Called when only the number of logins is needed, and not the actual logins (which avoids prompting the user for a Master Password, as the logins don't need to be decrypted).

unsigned long countLogins(
  in AString aHostname,
  in AString aActionURL,
  in AString aHttpRealm
);
Parameters
aHostname
The hostname to which to restrict searches, formatted as a URL. For example, "https://www.bar.com". To match all hostnames, specify "" (empty string). A value of null will cause countLogins() to not match any logins.
aActionURL
For form logins, this parameter should specify the URL to which the form will be submitted. To match any form login, specify "" (empty string). To not match any form logins (For example when interested in protocol logins only), specify null.
aHttpRealm
For protocol logins, specify the HTTP Realm for which the login applies; this is obtained from the WWW-Authenticate header (see RFC 2617). To match any protocol login, specify "" (empty string). To not match any protocol logins (For example when interested in form logins only), specify null.
Return value

The number of logins matching the parameters passed.

Requires Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

fillForm()

Fills out a form with login information, if appropriate information is available.

Note : This method will attempt to fill out the form regardless of the setting of the signon.autofillForms preference.

boolean fillForm(
  in nsIDOMHTMLFormElement aForm
);
Parameters
aForm
The HTMLform to attempt to fill out.
Return value

true if the form was successfully filled out; otherwise false.

findLogins()

Searches for logins matching the specified criteria. Called when looking for logins that might be applicable to a given form or authentication request.

void findLogins(
  out unsigned long count,
  in AString aHostname,
  in AString aActionURL,
  in AString aHttpRealm,
  [retval, array, size_is(count)] out nsILoginInfo logins
);
Parameters
count
The number of elements in the returned array. JavaScript callers can simply use the array's length property and supply a dummy argument for this parameter.
aHostname
The hostname to restrict searches to, formatted as a URL. For example, "https://www.bar.com".
aActionURL
For form logins, this parameter should specify the URL to which the form will be submitted. For protocol logins, specify null. An empty string ("") will match any value (except null).
aHttpRealm
For protocol logins, specify the HTTP Realm for which the login applies; this is obtained from the WWW-Authenticate header (see RFC 2617). For form logins, this parameter should be null. An empty string ("") will match any value (except null).
logins
An array of nsILoginInfo objects.
Example

This method can be called from JavaScript like this:

 var logins = myLoginMgr.findLogins({}, hostname, ...);

getAllDisabledHosts()

Returns a list of all hosts for which login saving is disabled.

void getAllDisabledHosts(
  [optional] out unsigned long count,
  [retval, array, size_is(count)] out wstring hostnames
);
Parameters
count
The number of elements in the returned array. JavaScript callers can simply use the array's length property and supply a dummy argument for this parameter.
hostnames
An array of hostname strings in URL format without a pathname. For example: "https://www.site.com".
Example

You can call this method from JavaScript like this:

 var disabledHosts = myLoginMgr.getAllDisabledHosts({});

getAllLogins()

Returns an array containing all logins recorded by the Login Manager.

If you just want to see if any logins are stored, use countLogins() instead. It's more efficient, and avoids the possibility of the user being prompted for their master password.

void getAllLogins(
  [optional] out unsigned long count,
  [retval, array, size_is(count)] out nsILoginInfo logins
);
Parameters
count
The number of elements in the returned array. JavaScript callers can simply use the array's length property and supply a dummy argument for this parameter.
logins
An array of nsILoginInfo objects containing all the logins the Login Manager has on record.
Example

You can call this method from JavaScript like this:

 var logins = myLoginMgr.getAllLogins({});

getLoginSavingEnabled()

Reports whether or not saving login information is enabled for a host.

boolean getLoginSavingEnabled(
  in AString aHost
);
Parameters
aHost
The hostname to check. This argument should be in the origin URL format, with no pathname. For example: "https://www.site.com".
Return value

true if login saving is enabled for the host, otherwise false.

modifyLogin()

Modifies an existing login by replacing it with a new one.

If newLoginData is a nsILoginInfo, all of the old login's nsILoginInfo properties are changed to the values from newLoginData (but the old login's nsILoginMetaInfo properties are unmodified).

If newLoginData is a nsIPropertyBag, only the specified properties will be changed. The nsILoginMetaInfo properties of oldLogin can be changed in this manner.

If the propertybag contains an item named "timesUsedIncrement", the login's timesUsed property will be incremented by the item's value.

void modifyLogin(
  in nsILoginInfo oldLogin,
  in nsISupports newLoginData
);
Parameters
oldLogin
The login to be modified.
newLoginData
The login information to replace the oldLogin with. This may be specified as either an nsILoginInfo or an nsIPropertyBag2 object.

removeAllLogins()

Removes all logins known by the Login Manager. This works without a need for the master password, if one is set.

void removeAllLogins();
Parameters

None.

removeLogin()

Removes a login from the Login Manager.

Note : The specified login must exactly match a stored login. However, the values of any nsILoginMetaInfo properties are ignored.

void removeLogin(
  in nsILoginInfo aLogin
);
Parameters
aLogin
The login to remove from the Login Manager. Only a login that is an exact match is deleted.

Requires Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)

searchLogins()

Searches for logins in the login manager's data store, returning an array of matching logins. If there are no matching logins, an empty array is returned.

void searchLogins(
  out unsigned long count,
  in nsIPropertyBag matchData,
  [retval, array, size_is(count)] out nsILoginInfo logins
);
Parameters
count
The number of elements in the returned array.
matchData
The data used for the search. This does not follow the same requirements as findLogins() for those fields; wildcard matches are not specified.
logins
An array of matching nsILoginInfo objects.
Example

This method can be called from JavaScript like this:

 var logins = myLoginMgr.searchLogins({}, matchData);
 var numLogins = logins.length;

setLoginSavingEnabled()

Enables or disables storing logins for a specified host. When login storing is disabled, the Login Manager won't prompt the user to store logins for that host. Existing logins are not affected.

void setLoginSavingEnabled(
  in AString aHost,
  in boolean isEnabled
);
Parameters
aHost
The hostname to adjust the setting for. This argument should be in the origin URL format, with no pathname. For example: "https://www.site.com".
isEnabled
If true, login saving is enabled for the specified host. If false, login saving is disabled.

See also

Étiquettes et contributeurs liés au document

 Contributeurs à cette page : Sheppy
 Dernière mise à jour par : Sheppy,