npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

my-user

v0.2.0

Published

My user management objects for me.

Downloads

3

Readme

my-user v.0.2.0

my-user is my simple user objects for me, supporting authentication.

User objects hold user id, authentication data, and other data.

Installation

npm install my-user

TypeScript support

Available. Requites TypeScript >= 2.0

Usage

Init UserConfig and create User:

var userconfig=require('my-user').init();

// Create user
var user=userconfig.create("user_id");


// Set password and extra data
user.setData({
    /* extra data */
    foo: "bar",
    hoge: new Date()
},"password");

//authenticate
console.log(user.auth("wrongpassword"));    //false
console.log(user.auth("password"));         //true

//read data
var data=user.getData();
console.log(data);

Versioning and auth methods

User objects have versions.

Different versions may have different auth methods.

var userconfig=require('my-user').init();

//Set salt length by bytes
userconfig.setSalt(1,16);	//version 1 -> 16 bytes

//User-defined salt generator
userconfig.setSalt(2,function(){
    return "static salt";
});

//Password hash function
userconfig.setPasswordHash(1,"md5");

//User-defined hash function
userconfig.setPasswordHash(2,function(salt,password){
    return salt+password;
});


var user=userconfig.create();

//indicate user version
user.setData({},"password",1);

console.log(user.version === 1);     //true

//if version is omitted, it will be the latest
user.setData({},"new_password");

console.log(user.version === 2);      //true

APIs

init([options])

Returns new instance of UserConfig.

  • options.freeze (boolean): Data returned by user.getData() is frozen by Object.freeze. (default: false)
  • options.deepcopy (boolean): Data passed to user.setData() is deeply cloned.

userconfig.create([userid])

Returns new instance of User.

userconfig.setSalt(version,bytes)

Set salt-generation function of version version to crypto.pseudoRandomBytes(bytes).

Salts will be represented by hex string.

userconfig.setSalt(version,func)

Set salt-generation function of version version to func.

func takes no argument and returns string.

userconfig.setPasswordHash(version,type)

Set password hash function of version version to type.

type is string representing hash function supported by crypto.

userconfig.setPasswordHash(version,func)

Set password hash function of version version to func.

func takes 2 arguments salt and password and returns string.

userconfig.getSalt([version])

returns salt-generation function of version version (the latest if omitted).

userconfig.getPasswordHash([version])

returns password hash function of version version (the latest if omitted).

user.id

User id string.

user.version

The version of user represented by integer.

user.salt

Salt string.

user.password

Hashed password string.

user.setData(data[, password][, version])

Set user's extra data, optionally password, and optionally version.

If version is omitted, it will be the latest.

password is required when password hash function changes by upgrading/downgrading.

user.writeData(data)

Partially overrides user's data by data.

This method does not change the version of user.

user.getData()

Returns user's current extra data.

user.auth(password)

Checks if password is currect. Returns boolean value.