Download the PHP package units/hasher without Composer

On this page you can find all versions of the php package units/hasher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hasher

Units — Hasher

Fingerprints. Same input, same answer, every time.

PHP's own hash(), hash_hmac() and hash_equals(), with a name and a version on top. No dependencies, no state.

The words

Hash — one way. hello always becomes the same 64 characters, and those characters never lead back to hello. For "is this the same?".

HMAC — a hash with a secret stirred in. Only a holder of the secret can reproduce it. For "was this really us?".

Salt — extra random input, so the same value gives a different hash. Off by default: a hash you cannot reproduce is useless for looking anything up.

Pepper — a secret mixed into a password before hashing, kept out of the database. Your application's call, not the unit's.

Is this the same?

Change one character and the answer changes completely. That is the whole point.

Was this really us?

The sender signs the body with the shared secret; you sign what arrived. Nobody without the secret can produce a match.

Compare, don't ===

=== stops at the first byte that differs, and the time that takes tells the caller how much of the guess was right. compare() does not, and it treats an empty value as "not a match":

verify() returns false for anything unusable, never an exception.

A different answer each time

salt() gives you 16 random bytes as hex. Use it when two identical rows must not produce two identical hashes — and remember the result is then no longer reproducible from the value alone.

Shape of the output

Encoding Looks like Use for
hex (default) 2cf24dba… databases, logs, shell
base64 LPJNul+wow4m… the same, 33% shorter
base64url LPJNul-wow4m… URLs, filenames, tokens
binary raw bytes feeding another binary function

Set it once; override it per call:

Algorithms

Algorithm Use it when
sha256 (default) almost always
sha512 you want more margin
sha3-512 a spec or a standard names it
blake2b you want a modern hash, fast on 64-bit
sha1 · md5 · ripemd160 never for new work — only to read values that already exist

Passwords do not live here

A fingerprint must be fast and repeatable. A password hash must be slow and never repeatable. Same word, opposite requirements — so passwords are units/password:

Never stretch() a password. It is a portable key stretch for legacy formats — still far too fast to protect a credential.

It knows its version

A hash outlives the code that made it. Keep the identity beside it, so a value found later can say what produced it:

Reference

Method Gives you
create(['algorithm' => …, 'encoding' => …, 'dna' => …]) a hasher
hash($data, ['algorithm' => …, 'encoding' => …, 'salt' => …, 'iterations' => …]) HashResult
hashBytes($bytes, $options) HashResult, for binary input
hmac($data, $secret, $options) HashResult, keyed
compare($a, $b) bool, timing-safe
verify($data, $expected, $options) bool, never throws
stretch($value, $salt = null, $iterations = 10000) HashResult
sha256() sha512() md5() sha3_512($data, $encoding = 'hex') string
salt($bytes = 16) random hex
algorithms() supports($name) what this PHP can actually do
algorithm() encoding() dna() whoami() help() itself

HashResult carries hash, algorithm, encoding, and salt and iterations when they were used. It is immutable, and (string) $result is the hash.

MIT · tests: composer test


All versions of hasher with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
patterns/unit Version ^1.0.1
patterns/value-object Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package units/hasher contains the following files

Loading the files please wait ...