Closed Bug 378667 Opened 19 years ago Closed 19 years ago

Better "passwords for given realm" query support

Categories

(Toolkit :: Password Manager, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9alpha8

People

(Reporter: johnath, Assigned: Dolske)

References

Details

Attachments

(2 files, 1 obsolete file)

AFAICT, the recommended way to ask PWMgr whether it has stored password(s) for a given realm is code like: function realmHasPasswords(location) { var realm = makeURI(location).prePath; var passwordManager = Components.classes["@mozilla.org/passwordmanager;1"] .getService(Components.interfaces.nsIPasswordManager); var e = passwordManager.enumerator; while (e.hasMoreElements()) { var next = e.getNext().QueryInterface(Components.interfaces.nsIPassword); if (!next) continue; if (realm == next.host) return true; } return false; } This is unfortunate since it's O(n) and also more lines of code than seem strictly necessary. In review comments for bug 377076, mconnor recommended a bug tracking this problem, after seeing the snippet above used. This is also the algorithm devmo recommends (ref: http://developer.mozilla.org/en/docs/Using_nsIPasswordManager ) so if this bug uncovers a pre-existing better way to do things, this is a reminder to me to update that wiki content.
The new password manager is a bit easier to use... var passwordManager = ...samething... var logins = passwordManager.getAllLogins(); //logins is a JS array return logins.some(function compare(t) { return t.hostname == hostname; }); It would probably be easy to extend getAllLogins() or findLogins() to take a hostname, since that's basically what they're hashed on internally. I was also considering a hasLoginsFor(hostname) interface at one point, but it didn't end up being necessary.
Status: NEW → ASSIGNED
Assignee: nobody → dolske
Status: ASSIGNED → NEW
OS: Mac OS X → All
Hardware: PC → All
Target Milestone: --- → Firefox 3 M8
Attached patch Patch for review, v.1 (obsolete) — — Splinter Review
(I edited the patch to remove some chunks from an overlapping patch, so it might not apply cleanly)
Attachment #276732 - Flags: review?(gavin.sharp)
oops: |count.value = 0;| at the top of _searchLogins should be deleted.
Comment on attachment 276732 [details] [diff] [review] Patch for review, v.1 >Index: toolkit/components/passwordmgr/src/storage-Legacy.js >+ * countLogins Wrong comment ^ >+ _searchLogins : function (hostname, formSubmitURL, httpRealm) { >+ var hostLogins = this._logins[hostname]; >+ if (hostLogins == null) { >+ count.value = 0; This needs to be removed, as you mention. >+ for each (var login in hostLogins) { >+ >+ // If search arg is null, skip login unless it doesn't specify a >+ // httpRealm (ie, it's also null). If the seach arg is an empty >+ // string, always match. >+ if (httpRealm == null) { >+ if (login.httpRealm != null) >+ continue; >+ } else if (httpRealm != "") { >+ // Make sure the realms match. If search arg is null, >+ // only match if login doesn't specify a realm (is null) >+ if (httpRealm != login.httpRealm) >+ continue; >+ } I believe this is equivalent to: if (httpRealm != login.httpRealm && httpRealm != "") continue; although the formSubmitURL equivalent isn't as easy to simplify, so perhaps you'd prefer just leaving it as is. >@@ -532,17 +583,21 @@ LoginManagerStorage_legacy.prototype = { > case STATE.ACTIONURL: >- entry.formSubmitURL = line.value; >+ var formSubmitURL = line.value; >+ if (!formSubmitURL && entry.httpRealm) >+ entry.formSubmitURL = null; >+ else >+ entry.formSubmitURL = formSubmitURL; Is this part of another patch? If not, please explain? Are there existing/forthcoming tests for this function?
Attachment #276732 - Flags: review?(gavin.sharp) → review+
Tests in bug 378667, need a patch that applies here so that I can review that patch.
Flags: in-testsuite?
(In reply to comment #6) > Tests in bug 378667 I meant bug 386005!
(In reply to comment #5) > although the formSubmitURL equivalent isn't as easy to simplify, so perhaps > you'd prefer just leaving it as is. I'll leave this; the logic gets a little confusing if it's condensed down a single statement. It also stays symmetric with the formSubmitURL case. > >@@ -532,17 +583,21 @@ LoginManagerStorage_legacy.prototype = { > > > case STATE.ACTIONURL: > >- entry.formSubmitURL = line.value; > >+ var formSubmitURL = line.value; > >+ if (!formSubmitURL && entry.httpRealm) > >+ entry.formSubmitURL = null; > >+ else > >+ entry.formSubmitURL = formSubmitURL; > > Is this part of another patch? If not, please explain? No, it's part of this patch. These two fields are both using null to indicate "doesn't apply here", and empty-string to indicate "applies, but no value set". [The STATE.REALM case already worked this way]. Setting a null value here is needed for calling _searchLogins() with a formSubmitURL value of null (otherwise it won't match a login you would expect it to). EG: _searchLogins("http://site.com", null, "Intranet Login")
Attachment #277825 - Flags: review?(gavin.sharp)
Attachment #276732 - Attachment is obsolete: true
Comment on attachment 277825 [details] [diff] [review] Patch for testcases, v.1 Haven't run these, but r=me assuming they pass!
Attachment #277825 - Flags: review?(gavin.sharp) → review+
Checked in. Checking in browser/base/content/pageinfo/security.js; /cvsroot/mozilla/browser/base/content/pageinfo/security.js,v <-- security.js new revision: 1.8; previous revision: 1.7 done Checking in toolkit/components/passwordmgr/public/nsILoginManager.idl; /cvsroot/mozilla/toolkit/components/passwordmgr/public/nsILoginManager.idl,v <-- nsILoginManager.idl new revision: 1.4; previous revision: 1.3 done Checking in toolkit/components/passwordmgr/public/nsILoginManagerStorage.idl; /cvsroot/mozilla/toolkit/components/passwordmgr/public/nsILoginManagerStorage.idl,v <-- nsILoginManagerStorage.idl new revision: 1.6; previous revision: 1.5 done Checking in toolkit/components/passwordmgr/src/nsLoginManager.js; /cvsroot/mozilla/toolkit/components/passwordmgr/src/nsLoginManager.js,v <-- nsLoginManager.js new revision: 1.13; previous revision: 1.12 done Checking in toolkit/components/passwordmgr/src/storage-Legacy.js; /cvsroot/mozilla/toolkit/components/passwordmgr/src/storage-Legacy.js,v <-- storage-Legacy.js new revision: 1.12; previous revision: 1.11 done Checking in toolkit/components/passwordmgr/test/unit/test_storage_legacy_1.js; /cvsroot/mozilla/toolkit/components/passwordmgr/test/unit/test_storage_legacy_1.js,v <-- test_storage_legacy_1.js new revision: 1.5; previous revision: 1.4 done Checking in toolkit/components/passwordmgr/test/unit/test_storage_legacy_2.js; /cvsroot/mozilla/toolkit/components/passwordmgr/test/unit/test_storage_legacy_2.js,v <-- test_storage_legacy_2.js new revision: 1.5; previous revision: 1.4 done
Status: NEW → RESOLVED
Closed: 19 years ago
Flags: in-testsuite? → in-testsuite+
Resolution: --- → FIXED
Product: Firefox → Toolkit
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: