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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jaimilgorajiya/password-utils

v1.2.0

Published

A robust Node.js package for secure password hashing, validation, comparison, and login rate limiting.

Readme

@jaimilgorajiya/password-utils

A robust, production-ready Node.js library for secure password management. Features bcrypt hashing, strength validation, comparison helpers, and login rate limiting.

Features

  • 🔒 Secure Hashing: Uses bcryptjs for industry-standard password hashing.
  • Validation: Custom rule-based password strength checking.
  • Rate Limiting: Built-in login attempt limiter to prevent brute-force attacks.
  • 📦 Dual Support: Works seamlessly with both CommonJS (require) and ES Modules (import).
  • 🔷 TypeScript: Includes full type definitions (.d.ts).

Installation

npm install @jaimilgorajiya/password-utils

Usage

1. Import the library

ES Modules (import)

import { 
  validatePassword, 
  hashPassword, 
  comparePassword, 
  loginRateLimiter 
} from '@jaimilgorajiya/password-utils';

CommonJS (require)

const { 
  validatePassword, 
  hashPassword, 
  comparePassword, 
  loginRateLimiter 
} = require('@jaimilgorajiya/password-utils');

2. Complete Registration & Login Flow

Here is how you would use password-utils in a deeper real-world context like an Express.js controller.

User Registration (Sign Up)

/* REGISTER CONTROLLER */
const registerUser = async (req, res) => {
  const { username, password } = req.body;

  // 1. Validate Password Strength
  const validation = validatePassword(password);
  if (!validation.isValid) {
    return res.status(400).json({ 
      message: 'Weak password', 
      errors: validation.errors 
    });
  }

  try {
    // 2. Hash Password securely
    const hashedPassword = await hashPassword(password);

    // 3. Save User to Database (Mock)
    // await db.users.create({ username, password: hashedPassword });

    res.status(201).json({ message: 'User registered successfully' });
  } catch (error) {
    res.status(500).json({ error: 'Server error' });
  }
};

User Login (Sign In)

/* LOGIN CONTROLLER */
const loginUser = async (req, res) => {
  const { username, password } = req.body;
  
  // 1. Check Rate Limit (Prevent Brute Force)
  // Identify by IP address or Username
  const attempt = loginRateLimiter(req.ip, 5, 60 * 1000); // 5 attempts per 60s
  
  if (!attempt.allowed) {
    return res.status(429).json({ message: attempt.message });
  }

  // Fetch user from DB
  const user = await db.users.findOne({ username });
  if (!user) return res.status(401).json({ message: 'Invalid credentials' });

  // 2. Compare Password
  const isMatch = await comparePassword(password, user.password);
  
  if (!isMatch) {
    return res.status(401).json({ message: 'Invalid credentials' });
  }

  res.json({ message: 'Login successful', token: 'abcd-1234' });
};

API Reference

| Function | Params | Returns | Description | |----------|-----------|---------|-------------| | validatePassword | (password) | { isValid, errors } | Validates password complexity. | | hashPassword | (password, salt=10) | Promise<string> | Hashes a password (bcrypt). | | comparePassword | (plain, hashed) | Promise<boolean> | Verifies password match. | | loginRateLimiter | (id, max=5, win=60k) | { allowed, msg } | In-memory rate limiter. |

Development & Maintenance

Running Tests

This project uses Jest for testing.

npm test

Publishing a New Version

  1. Update Version: Bump the version in package.json.
    npm version patch  # or minor/major
  2. Run Tests: Ensure everything is stable.
    npm test
  3. Publish: Push to npm registry.
    npm publish

License

MIT © Jaimil Gorajiya