function testFindOne($i, $pos, $idList)
{
    $hash = new Hashing($idList);
    $result = $hash->findNode($pos);
    assert($i == $result);
    echo '.';
}
 /**
  * @param $key
  * @return Redis
  */
 private function getRedis($key)
 {
     $pos = $this->getHash($key);
     $node = $this->hash->findNode($pos);
     $conn = $this->nodeMap[$node];
     $redis = $this->connect($conn);
     //echo "$key => $conn\n";
     return $redis;
 }
Beispiel #3
0
 /**
  * Is password library supported?
  *
  * @return boolean
  */
 function isSupported()
 {
     static $supported;
     if ($supported === null) {
         $supported = false;
         if (Hashing::initialize()) {
             /**
              * Check if current PHP version is compatible with the library
              *
              * taken from PasswordCompat\binary\check()
              *
              * we can't use that directly because namespaces may not be supported
              * which will cause a syntax error
              */
             if (function_exists('crypt')) {
                 $hash = '$2y$04$usesomesillystringfore7hnbRJHxXVLeakoG8K30oukPsA.ztMG';
                 $supported = crypt("password", $hash) == $hash;
             }
         }
     }
     return $supported;
 }
Beispiel #4
0
 * First step of setup: database creation (action of index.php)
 * @copyright  Copyright (c) 2014 PHPBack
 * @author       Ivan Diaz <*****@*****.**>
 * @author       Benjamin BALET<*****@*****.**>
 * @license      http://opensource.org/licenses/GPL-3.0 GPL-3.0
 * @link            https://github.com/ivandiazwm/phpback
 * @since         1.0
 */
define('APPLICATION_LOADED', true);
define('BASEPATH', '.');
//Make this script work with nginx
error_reporting(E_ALL);
ini_set('display_errors', 1);
include 'pretty_message.php';
include '../application/libraries/Hashing.php';
$hashing = new Hashing();
/**
 * Redirect to the initial form and pass to the page an array containing :
 * 1. Previous entered values
 * 2. Error messages if any
 * @param string $url URL of the action page
 * @param array $data array containing the previous posted values in the form
 */
function redirectPost($url, array $data)
{
    echo '<html><head>
        <script type="text/javascript">
            function close() {
                document.forms["redirectpost"].submit();
            }
        </script>
 /**
  * Encrypt user passwords for database storage.
  * The username is used as a unique salt to make dictionary
  * attacks against a compromised database more difficult.
  * @param $username string username (kept for backwards compatibility)
  * @param $password string unencrypted password
  * @param $encryption string optional encryption algorithm to use, defaulting to the value from the site configuration
  * @param $legacy boolean if true, use legacy hashing technique for backwards compatibility
  * @return string encrypted password
  */
 function encryptCredentials($username, $password, $encryption = false, $legacy = null)
 {
     if (!isset($legacy)) {
         $legacy = !Hashing::isSupported();
     }
     if ($legacy) {
         $valueToEncrypt = $username . $password;
         if ($encryption == false) {
             $encryption = Config::getVar('security', 'encryption');
         }
         switch ($encryption) {
             case 'sha1':
                 if (function_exists('sha1')) {
                     return sha1($valueToEncrypt);
                 }
             case 'md5':
             default:
                 return md5($valueToEncrypt);
         }
     } else {
         return Hashing::getHash($password);
     }
 }