Last active
December 15, 2015 17:09
-
-
Save flacodirt/5294611 to your computer and use it in GitHub Desktop.
Gets hash of provided plaintext passphrase using crypt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* getPassphraseHash | |
* | |
* Gets hash of provided plaintext passphrase using crypt | |
* | |
* @author https://gist.github.com/dirte | |
* @var string $rounds If supported, the number of rounds to loop the hash which increases security | |
* @var string $algo Crypt algorithm | |
* @var string $salt Uniqid with more entropy | |
* @var string $cryptSalt Salt to use in crypt | |
* @param string $passphrase Plaintext passphrase to hash | |
* @return string Hashed passphrase | |
*/ | |
public function getPassphraseHash($passphrase) { | |
// Select highest available Crypt algorithm | |
$rounds=''; | |
if (CRYPT_SHA512 == 1): | |
$algo='6'; | |
$rounds='$rounds=5046'; | |
elseif (CRYPT_SHA256 == 1): | |
$algo='5'; | |
$rounds='$rounds=5045'; | |
elseif (CRYPT_BLOWFISH == 1): | |
if (PHP_VERSIONID < 50307): | |
$algo='2a'; | |
else: | |
$algo='2y'; | |
endif; | |
endif; | |
$salt = uniqid('', true); | |
$cryptSalt = '$'.$algo.$rounds.'$'.$salt; | |
$hashedPassphrase = crypt($passphrase, $cryptSalt); | |
return $hashedPassphrase; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment