Tiny user management with SQLite. Lauer performs all the usual operations: creating users, login, verification, password reset and storing data. It's lightweigt and portable.
npm install lauer
var lauer = require("lauer");
var users = new lauer({db: "/tmp/lauer.sqlite"});
users.create({
username: "user1",
email: "user@example.com",
password: "gu3ssme!1",
verfified: 1,
}, function(err, result){
console.log(err, result);
users.login("user1", "gu3ssme!1", function(err, result){
console.log(err, result);
});
});
Create a new instance of Lauer
. opts
:
{
iterations: 4096, // number of iterations used by `pbkdf2`
db: "lauer.sqlite" // path to sqlite database
}
new
is true, if an empty database was created.
Create and return a random salt.
Create and return a salted password hash.
Slugify a string.
Create a user. user
:
{
username: "user1", // user name
email: "user@example.com", // email address
password: "gu3ssme!1", // password
verfified: 0, // 0 = user pending verfication, 1 = instantly active (see lauer.verify)
level: 0, // level (may be used by you to dertemine wo is an admin)
data: {} // user-defined data object
}
result
:
{
id: 1, // user id
username: "user1", // user name
verification: "<hexstr>" // verification string (see lauer.verify)
}
Get a user object. The first parameter may be an id
or username
.
result
:
{
id: 1, // user id
username: "user1", // user name
email: "user@example.com", // email
verified: 0, // verification status (0 = false, 1 = true)
level: 0, // level (may be used by you to dertemine wo is an admin)
created: 1234567890, // time user was created
updated: 1234567890, // time user was last changed
lastlogin: 1234567890, // time of last login
data: {} // user-defined data object
}
Get a user object. The first parameter may be username
or email
.
result
:
{
id: 1, // user id
username: "user1", // user name
level: 0, // level (may be used by you to dertemine wo is an admin)
lastlogin: 1234567890 // time of last login
}
Delete user with id
.
Verify user with verification
. If verfification is successful, verified
will be set to 1 and the user may log in.
result
:
{
id: 1, // user id
username: "user1", // user name
level: 0, // level (may be used by you to dertemine wo is an admin)
lastlogin: 1234567890 // time of last login
}
Reset verification and create new verification string.
result
:
{
id: 1, // user id
username: "user1", // user name
email: "user@example.com", // email
verification: "<hexstr>" // verification string (see lauer.verify)
}
Create new verification string without resetting verification. Useful for changing forgotten passwords.
result
:
{
id: 1, // user id
username: "user1", // user name
email: "user@example.com", // email
verification: "<hexstr>" // verification string (see lauer.verify)
}
Check if a username
is available.
lauer.change(username||email, verification||current_password, new_password, function(err, result){})
Change password for a user identified by username
or email
.
The second parameter may either be the users current password or a verification tring created by lauer.verification
.
result
:
{
id: 1, // user id
username: "user1" // user name
}
Change user data.
result
:
{
id: 1, // user id
username: "user1" // user name
}