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

proof-of-login

v1.0.0

Published

a proof-of-work for your login or registration endpoints

Downloads

6

Readme

proof-of-login

a proof-of-work for your login or registration endpoints

To secure open endpoints like login or registration you might like to add some extra hurdle to the client side.

This package provides methods to create a challenge on the server, which needs be solved on the client side by calculating a nonce. This nonce must match the required complexity of a proof-of-work (PoW).

This nonce together with the challenge is provided on login/ registration and can be easily validated on the server side with a verify method.

How does it work?

  1. server creates challenge which contains complexity, the required hash alogithm for solving, timestamp and a random part.
  2. server signs that challenge with a secret
  3. server provides challenge to client (browser)
  4. client needs to calculate a nonce for that challenge. That nonce together with challenge is hashed and the resulting hash needs to match the required complexity (PoW)
  5. If a suitable nonce was found the client provides the challenge with the nonce back to the server
  6. The server calculates again the hash from challenge and nonce and verifies that the complexity required is given.

The library uses (both on server and client) the webcrypto API and supports the following hashing algorithms:

  • SHA-1
  • SHA-256 (default)
  • SHA-384
  • SHA-512

Usage

On Server

import { Challenge, Verifier } from 'proof-of-login'

const SECRET = 'never change me'
const challenger = new Challenge(SECRET)
const verifier = new Verifier(challenger)

const complexity = 11
const challenge = challenger.create(complexity)

// => send this challenge to the client

At client

import { solve } from 'proof-of-login'

// => challenge from server
const challenge = 'BQEAAAF9hH/Xb2keJ9PHOZapw9zPXSVyjYmqEPpmGew4pFyTDMY833aTb3KgrJU94H070XFf8IYKSsCR3PGbZA=='
const nonce = await solve(challenge) // might take seme time
//= AAABfYR/17jQB6aVseAeQWHm4gBZo2kT

// => send back `challenge` and `nonce` to server

Back on server

//...
const isValid = await Verifier.verify(challenge, nonce)

Time needed to calculate nonce

Depending on the complexity the time on average needed to calculate the nonce ca. doubles for each increase in complexity. For a complexity of 21 around 4 minutes must be spent on average *).

Please note, in case of a very lucky guess the time to calculate the nonce can still be in the milliseconds.

benckmark

Complexity versus Time in logarithmic scale

*) Results will vary depending on the processing power available.

Security considerations

To prevent brute force password this library increases the computational efforts on the client side to obtain a result for a password try.

Nonetheless additional measures must be taken into account on the server side to prevent trickeries with lower computational efforts.

Replay attacks

To prevent replay attacks consider storing the created challenges on the server side. Only if a valid challenge can be found the verification of the nonce is started.

After any succussful or unsuccessful verification delete the challenge and provide a fresh one.

Fresh challenge attacks

Due to the nature of the unprotected endpoints an attacker can always request a fresh challenge with a low computational complexity.

Therefor a challenges complexity must always be checked with the number of failed attempts. You may use the username or IP-Address for counting those attempts.

Example app

A sample application simulating a browser based login can be found at ./example

  1. clone this project: git clone --depth 10 https://github.com/spurreiter/proof-of-login
  2. Install dependencies: npm i
  3. Run example: npm run example
  4. Browse to: http://localhost:3030
  5. Click on "login"
  6. Try several logins with a wrong password. The time to solve the challenge increases with the number of failed login attempts.

License

MIT licensed