salt . $security['server_crypto_key']), 0, 22);
$salt = '$2a$' . $this->cost . '$' . $combined_salt . '$';
return crypt($this->password, $salt);
} else {
// Returns false if PHP version is not higher than 5.3.0 (which implements the Blowfish encruption mechanism).
return false;
}
}
/**
* Generates a valid 22 character random salt (using the correct valid characters).
* @return string A valid random 22 character salt.
*/
public function RandomSalt() {
$chars = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$randomsalt = (string) null;
for ($i = 0; $i < 22; $i++)
$randomsalt.=$chars[rand(0, 63)];
return $randomsalt;
}
/**
* Breaks the generated bcrypt string down to extract the various parts (the salt and the hash from the entire string)
* @param string $crypto A generated Blowfish hash.
* @return object Split parts of the cyrpto string.
*/
public function CryptParts($crypto) {
$algoritm = substr($crypto, 0, 4);
$cost = substr($crypto, 4, 2);
$salt = substr($crypto, 7, 22);
$hash = substr($crypto, 29);
$parts = array(
'Algorithm' => $algoritm,
'Cost' => $cost,
'Salt' => $salt,
'Hash' => $hash,
);
return (object) $parts;
}
}
?>