Skip to content

Fix case-sensitive username comparison in WinVaultKeyring#741

Open
veeceey wants to merge 3 commits intojaraco:mainfrom
veeceey:fix/issue-736-winvault-case
Open

Fix case-sensitive username comparison in WinVaultKeyring#741
veeceey wants to merge 3 commits intojaraco:mainfrom
veeceey:fix/issue-736-winvault-case

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 13, 2026

Fixes #736

The WinVaultKeyring backend was comparing usernames with strict case-sensitive equality (res['UserName'] != username), which doesn't match how Windows itself handles credentials — Win32Cred treats usernames case-insensitively.

This caused confusing behavior where storing a password for USER and then retrieving it as user would silently fail, and subsequent set_password calls with different casing would create orphaned compound entries.

Changes:

  • Added a _username_match helper that does case-insensitive comparison, handling None values correctly
  • Applied it in _resolve_credential so get_password / get_credential find credentials regardless of username casing
  • Applied it in set_password so updating a password for the same user with different casing just overwrites in place instead of unnecessarily creating a compound {username}@{service} entry
  • Applied it in delete_password so deletion works regardless of username casing
  • Added unit tests covering all the above scenarios (mocked, so they run on all platforms)

Test results:

All existing tests continue to pass. The new tests in TestUsernameMatch and TestWinVaultCaseInsensitive cover the case-insensitive matching behavior across get, set, delete, and credential resolution.

The WinVaultKeyring backend was comparing usernames with exact
case-sensitive equality, causing inconsistent behavior on Windows
where usernames are case-insensitive. For example, storing a password
for 'USER' and then retrieving it with 'user' would fail to find
the credential.

Introduce a _username_match helper for case-insensitive comparison
and apply it in _resolve_credential, set_password, and delete_password.

Also skip redundant compound-name creation in set_password when the
same user (regardless of case) updates their password for a service.

Fixes jaraco#736
Replace the fake_read function with a dict lookup so there's
no unreachable fallback return statement at line 158.
@veeceey
Copy link
Author

veeceey commented Feb 16, 2026

The Windows test failures look like they might be pre-existing/infra-related rather than caused by this change. Happy to investigate further if needed though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WinVaultKeyring backend does not always accept case-insensitive usernames

2 participants