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

passim

v1.0.0

Published

A TypeScript package for Password similarity checking using n-grams.

Readme

Passim (TypeScript)

Passim is a lightweight, secure TypeScript library for checking password similarity during password changes or resets. It ensures users don't reuse passwords that are too similar to their previous ones, enhancing security in authentication systems. This version (v1) uses an n-gram-based approach, with a future v2 planned to leverage homomorphic encryption for improved security.

Features

  • Secure password hashing with bcrypt.
  • Similarity checking using n-gram sketches.
  • Configurable parameters (n-gram size, similarity threshold, etc.).

Installation

Install via npm:

npm install passim

Or from source:

git clone https://github.com/nasredeenabdulhaleem/passim-ts.git
cd passim-ts
npm install
npm run build

Dependencies

  • Node.js 14+
  • bcrypt (included in package)

Usage

import { Passim } from "passim";

// Initialize Passim with default settings
const p = new Passim();

// Store an initial password
(async () => {
  const [hash, sketch] = await p.storePassword("Password123");
  console.log(`Stored hash: ${hash.slice(0, 10)}...`);
  console.log(`Stored sketch:`, sketch);

  // Check a similar password
  const newPassword = "Password124";
  const isSimilar = p.checkSimilarity(sketch, newPassword);
  console.log(`'${newPassword}' is${isSimilar ? " " : " not "}too similar`);

  // Attempt to change password
  const [success, [newHash, newSketch]] = await p.changePassword(
    hash,
    sketch,
    "TotallyNew"
  );
  console.log(`Password change: ${success ? "Accepted" : "Rejected"}`);
})();

API Documentation

Configuration

Passim supports customization via constructor parameters:

  • nGramSize (number, default: 3): Size of n-grams for similarity checking.
  • similarityThreshold (number, 0-1, default: 0.5): Proportion of matching n-grams that flags a password as "too similar."
  • numNgramsToStore (number, default: 5): Maximum n-grams stored in the sketch.

Example:

const p = new Passim(4, 0.7, 3);

Methods

storePassword

Stores a password by generating a bcrypt hash and similarity sketch.

  • Input: password (string)
  • Output: Promise resolving to [hash: string, sketch: Set]

checkSimilarity

Checks if a new password is too similar to an old one.

  • Input: oldSketch (Set), newPassword (string)
  • Output: boolean (true if too similar)

changePassword

Attempts to change a password, rejecting it if too similar.

  • Input: oldHash (string), oldSketch (Set), newPassword (string)
  • Output: Promise resolving to [success: boolean, [newHash: string, newSketch: Set] | [null, null]]

Security Notes

  • Password Hashing: Uses bcrypt with a cost factor of 10.
  • Similarity Sketch: Stores hashed n-grams, not plaintext. However, this method may leak structural info (e.g., common trigrams). A future v2 will use homomorphic encryption to eliminate this risk.
  • Storage: Store hash and sketch securely (e.g., in a database with access controls).

Roadmap

  • v2: Replace n-gram sketches with homomorphic encryption.
  • Add more similarity metrics (e.g., edit distance).
  • Expand test coverage.

Contributing

Open issues or submit pull requests at: github.com/nasredeenabdulhaleem/passim-ts

License

MIT License © 2025 Abdulhaleem Nasredeen