PasswordSafe and multiple users

Planned

I'm using PasswordSafe in my plugin to store the authentication details for user connections to a database. The service name for the settings are currently keyed to the hostname:port so users with the same username will not clash.

The issue I'm running into is that PasswordSafe is only storing the password for a single user. That is, if I use the same hostname:port, but with different user names then when creating/editing details for one, the password for the other gets removed.

When getting the password, I'm using:

    val credentialAttributes = CredentialAttributes(serviceName, username)
return PasswordSafe.instance.get(credentialAttributes)?.getPasswordAsString()

and when setting the password, I'm using:

    val credentialAttributes = CredentialAttributes(serviceName, username)
PasswordSafe.instance.set(credentialAttributes, password?.let { Credentials(username, it) })

Do I need to remove the username from the CredentialAttributes object? Should I be including the username in the service name?

If I remove the username from the CredentialAttributes object, will I need to support the current code for compatibility with existing credential store details?

Thanks in advance,

Reece

Please sign in to leave a comment.