🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

better-sqlite3-plus

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-sqlite3-plus

A collection of functions that can be easily applied to better-sqlite3 database instances

npmnpm
Version
1.0.0
Version published
Weekly downloads
1
-50%
Maintainers
0
Weekly downloads
 
Created
Source

better-sqlite3-plus

This module is a collection of functions that can be added to your sqlite3 database instance. The aim is to provide common database functionality that will speed up development of features commonly found a database.

crypto

genHash

Generates a hash value based on the provided string input

Parameters

  • data (Required): A string representing the value to be hashed
  • algorithm (Default: sha256): The hashing algorithim to use
  • encoding (Default: hex): The encoding to be used when generating the output
import Database from 'better-sqlite3';
import bs3plus from 'better-sqlite3-plus';

const db = new Database('test.db');

bs3plus.crypto(db);

// using all three parameters
const { hash } = db
  .prepare(`select genHash(?, ?, ?) as hash`)
  .get('string to hash', 'sha256', 'hex');

// using two parameters with default output of hex
const { hash } = db.prepare(`select genHash(?, ?) as hash`).get('string to hash', 'sha256');

// using one parameter with default output of hex hashed with sha256
const { hash } = db.prepare(`select genHash(?) as hash`).get('string to hash');

genPasswordHash

Generates a password hash value based on the provided inputs

Parameters

  • password (Required): The password that will be used to generate the hash
  • salt (Required): The salt value used to enhance the security of the password
  • iterations (Default: 500): Number of iterations to use when generating the hash
  • keyLength (Default: 32): The length of the generated hash value
  • algorithm (Default: sha512): The algorithm to use when generating the has value
  • encoding (Default: hex): The encoding to be used when generating the output
import Database from 'better-sqlite3';
import bs3plus from 'better-sqlite3-plus';

const db = new Database('test.db');

bs3plus.crypto(db);

// using all parameters to create a password hash
const { hash } = db
  .prepare(`select genPasswordHash(?, ?, ?, ?, ?, ?) as hash`)
  .get('password1!', 'randomSaltValue', 500, 32, 'sha512', 'hex');

// using all but one parameter to create a password hash using hex output
const { hash } = db
  .prepare(`select genPasswordHash(?, ?, ?, ?, ?) as hash`)
  .get('password1!', 'randomSaltValue', 500, 32, 'sha512');

// using all but two parameters to create a password hash using hex output and sha512 to generate
const { hash } = db
  .prepare(`select genPasswordHash(?, ?, ?, ?) as hash`)
  .get('password1!', 'randomSaltValue', 500, 32);

// using three parameters to create a password hash using hex output and sha512 to generate, with a
// key length of 32 bytes
const { hash } = db
  .prepare(`select genPasswordHash(?, ?, ?) as hash`)
  .get('password1!', 'randomSaltValue', 500);

// using three parameters to create a password hash using hex output and sha512 to generate, with a
// key length of 32 bytes and 500 iterations to make the generated hash harder to brute force
const { hash } = db
  .prepare(`select genPasswordHash(?, ?) as hash`)
  .get('password1!', 'randomSaltValue');

genSalt

Generates a salt value based on the provided inputs

Parameters

  • size (Default: 32): The size of the salt value in bytes
  • encoding (Default: hex): The encoding to be used when generating the output
import Database from 'better-sqlite3';
import bs3plus from 'better-sqlite3-plus';

const db = new Database('test.db');

bs3plus.crypto(db);

// using all parameters to create a salt value with the given parameters
const { salt } = db.prepare(`select genSalt(?, ?) as salt`).get(32, 'hex');

// using one parameter to generate a salt value with hex outpu
const { salt } = db.prepare(`select genSalt(?) as salt`).get(32);

// using the default parameters of 32 bytes and hex to generate a random salt value
const { salt } = db.prepare(`select genSalt() as salt`).get();

FAQs

Package last updated on 07 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts