Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
larvituser
Advanced tools
User module for node.js
First fire up the library connections like this:
const userLib = require('larvituser');
userLib.dataWriter.mode = 'master'; // Used for standalone use. If multiple applications connect via rabbitMQ the other should be "slave"
Create a new user in the database, do like this:
const userData = {
'firstname': 'Nisse',
'lastname': 'Nilsson',
'role': [
'user',
'subscriber'
]
}
userLib.create('myUsername', 'myPassword', userData, function(err, user) {
console.log('New user UUID: ' + user.uuid);
});
To fetch a user from database based on username and password, do like this:
userLib.fromUserAndPass('myUsername', 'myPassword', function(err, user) {
if (err) {
throw err;
}
if ( ! user) {
// No match found, or other more serious error
} else {
console.log('Fetched user ID: ' + user.id);
}
});
List multiple users
const users = new userLib.Users();
users.get(function(err, userList) {
if (err) throw err;
console.log(userList); // An array of objects
});
userLib.addUserField(userUuid, fieldName, fieldValue, function(err) {
// Field have been added
});
userLib.checkPassword('passwordToTest', 'theHashToTestAgainst', function(err, result) {
// Result being either true or false
});
userLib.create('username', 'password', {'firstname': 'John', 'lastname': 'Smith'}, function(err, user) {
console.log(user.uuid); // 91f15599-c1fa-4051-9e0e-906cab9819fe (or rather, a random Uuid)
});
Or set an Uuid manually like this:
userLib.create('username', 'password', {'firstname': 'John', 'lastname': 'Smith'}, 'f9684592-b245-42fa-88c6-9f16b9236ac3', function(err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3
});
Will fetch the first occurance in the database with this field name and field value.
userLib.fromField('firstname', 'John', function(err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3
});
Will fetch the first occurance in the database that matches all these field names and field values
userLib.fromFields({'firstname': 'John', 'lastname': 'Smith'}, function(err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3
});
userLib.fromUsername('username', function(err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3 or user will be false if no user is found
});
userLib.fromUuid('f9684592-b245-42fa-88c6-9f16b9236ac3', function(err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3
});
userLib.getFieldData('f9684592-b245-42fa-88c6-9f16b9236ac3', 'firstname', function(err, data) {
console.log(data); // ['John'] - Observe this will always be an array with values, since a field can hold several values
});
IMPORTANT!!! Will clear all data not given in the fields parameter
userLib.replaceUserFields('f9684592-b245-42fa-88c6-9f16b9236ac3', {'lastname': ['Smith', 'Johnsson']}, function(err) {
// The field "lastname" will now be replaced with the two values "Smith" and "Johnsson"
// And all other fields will be removed
userLib.getFieldData('f9684592-b245-42fa-88c6-9f16b9236ac3', 'lastname', function(err, data) {
console.log(data); // ['Smith', 'Johnsson']
});
});
userLib.rmUserField('f9684592-b245-42fa-88c6-9f16b9236ac3', 'lastname', function(err) {
userLib.fromUuid('f9684592-b245-42fa-88c6-9f16b9236ac3', function(err, user) {
console.log(user.fields); // {'firstname': ['John']}
});
});
userLib.setPassword('f9684592-b245-42fa-88c6-9f16b9236ac3', 'newSuperSecretPwd', function(err) {
// Now the users password is updated to "newSuperSecretPwd"
});
To disable a login, use boolean false as the new password:
userLib.setPassword('f9684592-b245-42fa-88c6-9f16b9236ac3', false, function(err) {
// This user can no longer login
});
userLib.setUsername('f9684592-b245-42fa-88c6-9f16b9236ac3', 'theNewUsername', function(err) {
// Now the users password is updated to "theNewUsername"
});
Run tests with mocha, make sure to have an empty database configured for tests to pass correctly!
The default config file will be application path/config/db_test.json
Or a custom one can be used by running
mocha test/test.js /path/to/config/db_another.json
FAQs
User module for node.js
The npm package larvituser receives a total of 406 weekly downloads. As such, larvituser popularity was classified as not popular.
We found that larvituser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.