password

Password strength analyzer, configurable generator and passphrase generator.

v1.0.0Security & encodingbundledimport "password";
Overview Installation Documentation Examples

Overview

Zero-dependency HolyPHP library for password strength analysis, configurable password generation, and memorable passphrase generation.

bundled — works offline zero dependencies auth entropy

Quick start

import "password";

// Analyze a password
$report = password_analyze("Tr0ub4dor&3!Extra");
println("Score: " . $report["score"] . " (" . $report["rating"] . ")");
println("Entropy: " . $report["entropy"] . " bits");

// Generate a 20-character password
$pw = password_generate(20);
println("Generated: " . $pw);

// Generate a 4-word passphrase
$phrase = password_passphrase(4, "-", true, true);
println("Passphrase: " . $phrase);

Installation

In a project

Inside a project (a folder with hphp.yaml, see Projects & packages):

hphp install password

This adds the library to hphp.yaml, installs it into .hphp/packages/password/ and pins the exact version in hphp.lock:

require:
  password: "^1.0"

Use it

import "password";

password is bundled with the compiler, so import "password"; also works in a single file without installing anything, and hphp install works offline.

Outside a project

hphp install password          # for your user, shared by all scripts
hphp create myapp                 # or start a project, then: hphp install password
Packagepassword
Version1.0.0 (follows the compiler)
Entry filepassword.hphp
Sourcepackages/lib/password ↗

Documentation

API Reference

password_analyze(string $password): array

Analyzes a password and returns an associative array with:

KeyTypeDescription
scoreintStrength score from 0 to 100
ratingstringOne of "very_weak", "weak", "fair", "strong", "very_strong"
entropyfloatEstimated entropy in bits (rounded to 2 decimals)
lengthintLength of the password
charsetsarrayMap of booleans: lower, upper, digits, symbols
feedbackarrayList of actionable suggestions to improve the password

Detects common passwords, repeated characters (aaa, 111), and sequential/keyboard patterns (123, abc, qwe).

password_generate(int $length = 16, array $options = []): string

Generates a random password of the requested length (1 to 1024).

Options:

OptionTypeDefaultDescription
lowerbooltrueInclude lowercase letters (a-z)
upperbooltrueInclude uppercase letters (A-Z)
digitsbooltrueInclude digits (0-9)
symbolsbooltrueInclude special symbols
exclude_ambiguousboolfalseExclude ambiguous characters (0, O, o, 1, l, I)
require_eachbooltrueGuarantee at least one character from each enabled class
customstring(unset)Use this exact character set instead of the boolean flags

password_passphrase(int $words = 4, string $separator = "-", bool $capitalize = false, bool $include_number = false): string

Generates a memorable passphrase from a built-in dictionary of 150 distinct English words.

Error Handling

All functions validate their inputs and throw an Exception prefixed with password::

Examples

01Quick start

Bundled with the compiler — import "password"; works offline in any file, or add it to a project with hphp install password.

import "password";

// Analyze a password
$report = password_analyze("Tr0ub4dor&3!Extra");
println("Score: " . $report["score"] . " (" . $report["rating"] . ")");
println("Entropy: " . $report["entropy"] . " bits");

// Generate a 20-character password
$pw = password_generate(20);
println("Generated: " . $pw);

// Generate a 4-word passphrase
$phrase = password_passphrase(4, "-", true, true);
println("Passphrase: " . $phrase);
Try it
hphp install password
hphp run main.hphp

Covered by the official test suite in tests/positive/lib_password.hphp.