1.1.2 • Published 3 years ago

hipstapas.core v1.1.2

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

hipstapas.core

Node.js CI

Easy and unobtrusive generation of secure strings, uuids, passphrases using EFF wordlists and random numbers.

This package is the core behind hipstapas.dev - the Hipster Password Helper As A Service, that lets you generate passphrases from anywhere in a second.

Table of content

Installation

This is a Node.js module.

Installation is done using the npm install command:

npm install hipstapas.core

Features

Quick Start

Import the module and call the generator (the default configuration values are documented in the Configuration Properties section):

  1. password
  2. uuid
  3. wordlist
  4. random
const hipstapasCore = require('hipstapas.core')

const password = hipstapasCore.password() 
// sample output: C7j|do]t!aj5r]#Od)&R+1UHC

const uuid = hipstapasCore.uuid()
// sample output: 43bf1afd-f9f5-4546-85ea-481b064d6d56

const wordlist =  hipstapasCore.wordlist()
// sample output: companion cope undermine tipoff calamari eternity

const random = hipstapasCore.random()
// sample output: 618554

Basic concepts

Input

Every method accepts an object as an input parameter, that has different configuration properties described in # Configuration options.

Validation

Every configuration property is of specific type and has a range of acceptable values. On each generation call, the passed values are validated regarding type and value range. If either of the two checks fails, the entire validation fails.

Output

The generation result is an object, that has three properties:

  • success: set to true if validation and generation were successful; false otherwise
  • result: an array with generated values when success = true
  • error: validation error description when success = false

Example of a successful uuid generation:

{
  success: true,
  result: [ '72e2aecd-3f5b-45c6-abe6-a438428822b3' ],
  error: ''
}

Examples of a failed uuid generation:

// wrong parameter type
{
  success: false,
  result: [],
  error: "Only numbers between 1 and 100 are allowed as values for the query parameter 'resultsCount'."
}
// wrong value range
{
  success: false,
  result: [],
  error: "The value of the query parameter 'resultsCount' must be between 1 and 100."
}

Configuration properties

One configuration property is supported by every generator:

Parameter nameTypeAllowed valuesDefault value
resultsCountNumber1..1001
Defines how many results should be generated at once

password

Parameter nameTypeAllowed valuesDefault value
alphabetSmallBooleantrue..falsetrue
If set to true the generation alphabet contains small characters: abcdefghijklmnopqrstuvwxyz
alphabetCapitalBooleantrue..falsetrue
If set to true the generation alphabet contains capital characters: ABCDEFGHIJKLMNOPQRSTUVWXYZ
alphabetNumberBooleantrue..falsetrue
If set to true the generation alphabet contains numbers: 0123456789
alphabetSpecialBooleantrue..falsetrue
If set to true the generation alphabet contains special characters: .,+-*/!?;:{}()[]%$&~#@
lengthMinNumber1..204816
Defines the minimal length of the generated phrase
lengthMaxNumber1..204832
Defines the maximal length of the generated phrase
resultsCountNumber1..1001
Defines how many results should be generated at once

uuid

Parameter nameTypeAllowed valuesDefault value
resultsCountNumber1..1001
Defines how many results should be generated at once

wordlist

Parameter nameTypeAllowed valuesDefault value
wordsNumber1..506
Defines how many results should be generated at once
resultsCountNumber1..1001
Defines how many results should be generated at once

random

Parameter nameTypeAllowed valuesDefault value
minNumber1..10485761
Defines the lower bound of the number generator
maxNumber1..10485761048576
Defines the upper bound of the number generator
sortBooleantrue..falsefalse
Sorts the generated number sequence
noDuplicatesBooleantrue..falsefalse
The generated number sequence should contain only unique numbers
resultsCountNumber1..1001
Defines how many results should be generated at once

Examples

const fiftyPasswords = hipstapasCore.password({ resultsCount: 50 })
const fiftyUuids = hipstapasCore.uuid({ resultsCount: 50 })
const fiftyPassphrases = hipstapasCore.wordlist({ resultsCount: 50 })
const fiftyRandomNumbers = hipstapasCore.random({ resultsCount: 50 })

/*
- generate 10 passphrases at once
- where each phrase is exactly 5 characters long
- excluding special and capital characters = using only small characters and numbers
*/
const options = {
  resultsCount: 10,
  lengthMin: 5,
  lengthMax: 5,
  alphabetSpecial: false,
  alphabetCapital: false
}
const passwords = hipstapasCore.password(options)
/* sample output:
{
  success: true,
  result: [
    '1p9d7', 'h88a2',
    'j6yzp', 'fftkg',
    '8d40c', 'uqp3q',
    'yj9wc', 'qjsch',
    'qnlrk', 'men3u'
  ],
  error: ''
}
*/

/*
- generate 5 random numbers at once
- every number should be >= 10 and <= 100
- sort the result sequence
- there should be no duplicates in the result sequence
*/
const optionsRandom = {
  resultsCount: 5,
  min: 10,
  max: 100,
  sort: true,
  noDuplicates: true
}
const randomNumbers = hipstapasCore.random(optionsRandom)
/* sample output: 
{ 
  success: true, 
  result: [ 30, 35, 52, 86, 88 ], 
  error: '' 
}
*/

License

MIT License