Download the PHP package yarri/password-hashing-machine without Composer

On this page you can find all versions of the php package yarri/password-hashing-machine. 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 password-hashing-machine

PasswordHashingMachine

Build Status

PasswordHashingMachine is tool for hashing and checking passwords using a required hashing algorithm, which must be registered from the outside.

More hashing algorithms can be registered to PasswordHashingMachine so legacy hashes can be also successfully handled.

Usage

1. Create the hashing machine

$hasher = new Yarri\PasswordHashingMachine();

2. Add one or more hashing algorithms

//  $hasher->addAlgorithm(
//    callback $hash_callback,
//    callback $is_hash_callback,
//    callback $check_password_callback
//  );

The first added algorithm is also the default hashing algorithm.

// default hashing algorithm - bcrypt
$hasher->addAlgorithm(
  function($password){ return password_hash($password,PASSWORD_BCRYPT); },
  function($password){ return !password_needs_rehash($password,PASSWORD_BCRYPT); },
  function($password,$hash){ return password_verify($password,$hash); }
);

Add another legacy hashing algorithms you need in your application.

// algorithm for md5 hashes with common salt
$hasher->addAlgorithm(
  function($password){ return md5(SITE_KEY.$password); },
  function($password){ return preg_match('/^[0-9a-f]{32}$/',$password); },
  function($password,$hash){ return md5(SITE_KEY.$password) === $hash; }
);

// algorithm for md5 hashes
$hasher->addAlgorithm(
  function($password){ return md5($password); },
  function($password){ return preg_match('/^[0-9a-f]{32}$/',$password); },
  function($password,$hash){ return md5($password) === $hash; }
);

In fact, for algorithms that provides hexadecimal hashes like md5, sha1, sha2, only the first callback is required.

$hasher->addAlgorithm(
  function($password){ return sha1($password); }
);

3. Use the machine

// hashing passwords
$hasher->hash("secret"); // e.g. '$2a$06$rLxnps2CuGC/9BPCq3ms..7uaWETN6GPiVMXYYGWqdQoMZsDQ/kFG'
$hasher->hash('$2a$06$rLxnps2CuGC/9BPCq3ms..7uaWETN6GPiVMXYYGWqdQoMZsDQ/kFG'); // rehash! e.g. '$2y$10$XPuxlYvtelPKTpYtBpeAxOEuidftLo/kGkmmZgtWCFehvWz2N43wy'
$hasher->hash(""); // e.g. '$2y$10$FZQFYFamZjnrUr1XvIdGTevA.iLQNSYvHXrP3LETn67AEGreuYCwe'

// hashing password but preserving valid hashes or empty parameters
$hasher->filter("secret"); // e.g. '$2a$06$rLxnps2CuGC/9BPCq3ms..7uaWETN6GPiVMXYYGWqdQoMZsDQ/kFG'
$hasher->filter('$2a$06$rLxnps2CuGC/9BPCq3ms..7uaWETN6GPiVMXYYGWqdQoMZsDQ/kFG'); // '$2a$06$rLxnps2CuGC/9BPCq3ms..7uaWETN6GPiVMXYYGWqdQoMZsDQ/kFG'
$hasher->filter(""); // ""
$hasher->filter(null); // null

// checking hashes
$hasher->isHash($hash); // true
$hasher->isHash("something"); // false
$hasher->isHash(""); // false

// verifying passwords
$hasher->verify($password,$hash); // true or false

After a successful verification, the legacy hash can be detected and the password re-hashing using the current hashing algorithm can be easily realized.

$hash = $user->getPasswordHash();
if($hasher->verify($password,$hash,$is_legacy_hash)){
  // the user is verified
  if($is_legacy_hash){
     // transparent password re-hashing using the current hashing algorithm
     $current_hash = $hasher->hash($password);
     $user->setPasswordHash($current_hash);
  }
}

Installation

The best way how to install PasswordHashingMachine is to use the Composer:

composer require yarri/password-hashing-machine

License

PasswordHashingMachine is free software distributed under the terms of the MIT license


All versions of password-hashing-machine with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.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 yarri/password-hashing-machine contains the following files

Loading the files please wait ....