Login/Password Management

Hi All,

 I am needing functionality in my plugin development that will allow me to store login/password combination on a per project basis. Is this something that is possible through the use of the normal API or will I need to come up with a solution of my own? I have looked at PasswordSafe class but that wasn't very friendly to me and I cannot find any examples. Does anyone have any suggestions or could possibly point me in the right direction? 



Comment actions Permalink

Update 2/27:

I believe I have figured it out finally. I was close but wasn't all the way there. I am using the Master Password here. There is another one for the in the memory that would be passwordSafe.getMemoryProvider()......


You need an instance of the PasswordSafe.

final PasswordSafeImpl passwordSafe = (PasswordSafeImpl) PasswordSafe.getInstance();

To Store Password:

Pretty self explanatory here. I am using my project as the reference, whatever class is doing the action in the requester (for example, it will show the class name when prompting for the password), the project name as the key and the actual password. This will allow me to store a password for a given project name as the key. I may add more to the key just to make it a little more unique but that's the general idea.

try {
passwordSafe.getMasterKeyProvider().storePassword(<Project Reference>, <Requester Class>, <KEY>, <PASSWORD_TO_STORE>));
} catch (PasswordSafeException e) {
System.out.println("Exception storing password for key [" + <PROJECT NAME> + "]" + e.toString());

To Retrieve Password:

Using the same provider you stored the password with, retrieve the password using the project reference, requestor class and key.

String password = passwordSafe.getMasterKeyProvider().getPassword(<Project Reference>, <Requester Class>, <KEY_USED_TO_STORE_PASSWORD>);

Hopefully this will help someone else that is needing this as well. It just wasn't that easy to find for me. 


Comment actions Permalink

Thanks for posting your findings here, Chris - that's very helpful.

Comment actions Permalink

Great explanation. Was easy to add. Thanks.

Comment actions Permalink

With the 2016.3 release(s) of the IDEs, this method will no longer work as a lot of it has been deprecated. Here is the new way I have implemented it:

// Saving Password
CredentialAttributes attributes = new CredentialAttributes("somekeyforstoring..ex:projectname", "username", this.getClass(), false);
Credentials saveCredentials = new Credentials(attributes.getUserName(), "password");
PasswordSafe.getInstance().set(attributes, saveCredentials);

// Retrieving Password
CredentialAttributes attributes = new CredentialAttributes("somekeyforstring..ex:projectname", "username", this.getClass(), false);
return PasswordSafe.getInstance().getPassword(attributes);

Please sign in to leave a comment.