Skip to content

An NPM package for generating and verifying simple, checksummed codes - for use as quickly verifiable coupon codes or similar.

License

Notifications You must be signed in to change notification settings

IWantPizza/simple-checksum-code-generator

Repository files navigation

Simple Checksum Code Generator

Generate and verify simple codes such as QZYZTHG. It should go without saying that is easily crackable and should not be used for secure applications. The last character of the code is a checksum function of the first characters. The idea is that if any of these characters are typoed, it can quickly be detected by the code verifier.

Installation

npm install @iwantpizza/simple-checksum-code-generator --save

Usage

The available configuration options are as follows:

Key Value Description
alphabet 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' The possible characters that a generated code can contain.
length 8 The length of generated codes.
salt 12 A salt for the checksum function. Note that for an alphabet of length 26, the salt 12 would have the same effect as the salt of 12 + (26*n) where n is any positive integer.

To change any of the available options, set them on the codeOptions object, for example:

import {CodeGenerator, CodeOptions, CodeVerifier} from '@iwantpizza/simple-checksum-code-generator/lib';

const codeOptions = new CodeOptions();
codeOptions.alphabet = 'ABCD';
const codeVerifier = new CodeVerifier(codeOptions);

Typescript

import {CodeGenerator, CodeOptions, CodeVerifier} from '@iwantpizza/simple-checksum-code-generator/lib';

const codeOptions = new CodeOptions();
const codeVerifier = new CodeVerifier(codeOptions);
const codeGenerator = new CodeGenerator(codeOptions);

// generate a code
codeGenerator.generate();

// check a code
codeVerifier.verify('ABC123');

Javascript

const simpleChecksumCodeGenerator = require("@iwantpizza/simple-checksum-code-generator/lib");
const codeOptions = new simpleChecksumCodeGenerator.CodeOptions();
const codeGenerator = new simpleChecksumCodeGenerator.CodeGenerator(codeOptions);
const codeVerifier = new simpleChecksumCodeGenerator.CodeVerifier(codeOptions);

// generate a code
codeGenerator.generate();

// check a code
codeVerifier.verify('ABC123');

About

An NPM package for generating and verifying simple, checksummed codes - for use as quickly verifiable coupon codes or similar.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published