noctahash
v0.1.0
Published
Memory-hard password hashing algorithm for Node.js and browsers
Maintainers
Readme
noctahash
Memory-hard password hashing algorithm for Node.js and browsers (WebAssembly).
Installation
npm install noctahashUsage
Node.js
const { hash, verify_password, generate_salt } = require('noctahash');
// Generate hash with automatic salt
const hashString = hash('password', null, 3, 64, 1, 'base64');
console.log(hashString);
// Verify password
const isValid = verify_password('password', hashString);
console.log(isValid);
// Custom salt
const salt = generate_salt(32);
const hashWithSalt = hash('password', salt, 3, 64, 1, 'base64');Browser
<script type="module">
import init, { hash, verify_password } from './pkg-web/noctahash.js';
await init();
const hashString = hash('password', null, 3, 64, 1, 'base64');
const isValid = verify_password('password', hashString);
</script>ES Modules
import init, { hash, verify_password, generate_salt } from 'noctahash';
await init();
const hashString = hash('password', null, 3, 64, 1, 'base64');
const isValid = verify_password('password', hashString);API
hash(password, salt, time_cost, memory_cost_mb, parallelism, encoding)
Creates a password hash.
password(string): Password to hashsalt(Uint8Array | null): Optional salt (32 bytes recommended)time_cost(number): Number of iterations (1-16777216)memory_cost_mb(number): Memory usage in MB (≥1)parallelism(number): Number of lanes (1-255, limited to 1 in WASM)encoding(string): "base64" or "hex"
Returns: string - Formatted hash string
verify_password(password, hash_string)
Verifies a password against a hash.
password(string): Password to verifyhash_string(string): Hash string to verify against
Returns: boolean - True if password matches
generate_salt(length?)
Generates a random salt.
length(number, optional): Salt length in bytes (default: 32)
Returns: Uint8Array - Random salt bytes
get_version()
Returns the algorithm version number.
Returns: number
Parameters
- time_cost: 1-16777216 (recommended: 2-3)
- memory_cost_mb: ≥1 (recommended: 32-64)
- parallelism: 1-255 (limited to 1 in WASM/browser)
- encoding: "base64" or "hex"
Building from Source
npm install
npm run buildFor web:
npm run build-webFor bundlers (webpack, rollup, etc.):
npm run build-bundlerLicense
MIT
Author
Tuna4L - GitHub
