#!/usr/bin/env php
<?php

/**
 * Password Validator
 *
 * @link      http://github.com/jeremykendall/authentication Canonical source repo
 * @copyright Copyright (c) 2013 Jeremy Kendall (http://about.me/jeremykendall)
 * @license   http://github.com/jeremykendall/authentication/blob/master/LICENSE MIT
 */

if (is_dir($vendor = __DIR__.'/../vendor')) {
    require($vendor.'/autoload.php');
} elseif (is_dir($vendor = __DIR__.'/../../../../vendor')) {
    require($vendor.'/autoload.php');
} else {
    die(
        'You must set up the project dependencies, run the following commands:'.PHP_EOL.
        'curl -s http://getcomposer.org/installer | php'.PHP_EOL.
        'php composer.phar install'.PHP_EOL
    );
}

// Taken from https://github.com/ircmaxell/password_compat/blob/master/version-test.php
$hash = '$2y$04$usesomesillystringfore7hnbRJHxXVLeakoG8K30oukPsA.ztMG';
$test = crypt("password", $hash);
$pass = $test == $hash;

\cli\line("%yTest for functionality of password_compat library:%y " . ($pass ? "%2%k Pass %2%k" : "%1%k Fail %1%k%n"));

if (!$pass) {
    \cli\line("%gPlease install Openwall's PHPass as an alternative to password_compat%g%n");
    \cli\line("%yInstallation instructions: %ghttp://jeremykendall.net/2013/12/13/installing-phpass-from-openwall-via-composer/%g%n");
}
