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

easy-express-captcha

v0.9.7

Published

A simple captcha generator for express

Downloads

11

Readme

easy-express-captcha

npm npm NPM GitHub last commit

Easy Express Captcha is a simple captcha middleware for Express.js. It uses custom captcha generation and verification to ensure fast and secure captcha handling. It's easy to integrate into any Express.js application and highly customizable to suit your needs. Perfect for protecting your forms from spam and bots.

You can check the demo here.

Installation

npm install easy-express-captcha

Usage

const express = require("express");
const captcha = require("easy-express-captcha");
const session = require("express-session");
const app = express();

app.use(
  session({
    secret: process.env.SECRET ?? "secret",
    resave: false,
    saveUninitialized: true,
  })
);

app.use(express.urlencoded({ extended: false }));
app.use(
  captcha({
    generator: {
      captcha: {
        length: 5,
      },
    },
    inputName: "captcha", // For more info, check the options section
  })
);

app.get("/", (req, res) => {
  const captcha = req.generateCaptcha();
  res.send(`
        <form action="/submit" method="post">
            ${captcha}
            <button type="submit">Submit</button>
        </form>
    `);
});

app.post("/submit", (req, res) => {
  if (req.validCaptcha) {
    res.send("Captcha is correct");
  } else {
    res.send("Captcha is incorrect");
  }
});

app.listen(3000, () => {
  console.log("Server is running on port 3000");
});

Result

Captcha Preview

Options

Generator Options

canvas

  • width: The width of the captcha. Default is 200.
  • height: The height of the captcha. Default is 100.

captcha

  • length: The length of the captcha. Default is 6.
  • spacing:
    • min: The minimum spacing between characters. Default is 30.
    • max: The maximum spacing between characters. Default is 40.

colors

  • background: The background color of the captcha. Default is random.
  • text: The text color of the captcha. Default is random.
  • noise: The noise color of the captcha. Default is random.
  • strokes: The strokes color of the captcha. Default is [random, random, random].

text

  • font: The font of the captcha. Default is 'bold 36px Arial'.
  • characters: The characters to use in the captcha. Default is 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'.

noise

  • density: The density of the noise. Default is 0.3.
  • curveCount: The number of curves in the noise. Default is 10.

strokes

  • count: The number of strokes in the captcha. Default is 4.
  • width: The width of the strokes. Default is 2.

Middleware Options

  • inputName: The name of the input field. Default is 'captcha'.
  • honeypot:
    • enabled: Enable honeypot fields. Default is false.
    • inputNames: Array of honeypot input names. Default is ['i am a robot'].
  • refresh:
    • enabled: Enable refresh button. Default is true.
    • path: The path to the refresh button. Default is '/refresh'.

License

MIT

Author

Made with ❤️ by kijmoshi

Support

Any support is appreciated. You can support me by giving a ⭐ to this repository or by buying me a coffee.