Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
larvituser
Advanced tools
User module for node.js
First fire up the library connections like this:
var userLib = require('larvituser');
Create a new user in the database, do like this:
var 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);
}
});
userLib.addUserField(userUuid, fieldName, fieldValue, function(err) {
// Field have been added
});
var uuid = userLib.bufferToUuid(new Buffer('f9684592b24542fa88c69f16b9236ac3', 'hex'));
console.log(uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3
This is used primarily for getting the binary buffer from the Uuid column in the database.
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
});
userLib.fromUsername('username', function(err, user) {
console.log(user.uuid); // f9684592-b245-42fa-88c6-9f16b9236ac3
});
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
});
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 292 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.