Securely store and manage passwords using platform specific backends. The backend on macOS is Keychain, on Linux it's the Secret Service, and on Windows it's Credential Vault.
npm install keytar
const keytar = require('keytar');
keytar.addPassword('com.mycompany.myapp', 'weblogin', 'myPassword');
>> true
keytar.getPassword('com.mycompany.myapp', 'weblogin');
>> 'myPassword'
keytar.replacePassword('com.mycompany.myapp', 'weblogin', 'myBett3rPassw0rd');
>> true
keytar.getPassword('com.mycompany.myapp', 'weblogin');
>> 'myBett3rPassw0rd'
keytar.removePassword('com.mycompany.myapp', 'weblogin');
>> true
Currently this library uses libsecret
so you may need to install it before npm install
ing.
Depending on your distribution, you will need to run the following command:
- Debian/Ubuntu:
sudo apt-get install libsecret-1-dev
- Red Hat-based:
sudo yum install libsecret-devel
- Arch:
sudo pacman -S libsecret
Get the stored password for the service
and account
.
service
- The string service name.
account
- The string account name.
Returns the string password or null
on failures.
Add the password
for the service
and account
to the keychain.
service
- The string service name.
account
- The string account name.
password
- The string password.
Returns true
on success, false
on failure.
Delete the stored password for the service
and account
.
service
- The string service name.
account
- The string account name.
Returns true
if a password has been deleted, or false
on failure.
Replace the password
for the service
and account
in the keychain.
This is a simple convenience function that internally calls
deletePassword(service, account)
followed by
addPassword(service, account, password)
.
service
- The string service name.
account
- The string account name.
password
- The string password.
Returns true
on success, false
on failure.
Find a password for the service
in the keychain.
service
- The string service name.
Returns the string password or null
on failures.
git clone git@github.com:mongodb-js/node-keytar.git ~/keytar;
cd ~/keytar;
npm install;
npm test;