49 return function_exists(
'crypt');
60 public function generate_hash (
string $pwd,
bool $locked = FALSE): string
64 if ($this->hash ==
"crypt/standard-des") {
66 for ($i = 0; $i < 2; $i++) {
69 } elseif ($this->hash ==
"crypt/enhanced-des") {
71 for ($i = 0; $i < 8; $i++) {
74 } elseif ($this->hash ==
"crypt/md5") {
76 for ($i = 0; $i < 8; $i++) {
80 } elseif ($this->hash ==
"crypt/blowfish") {
82 for ($i = 0; $i < CRYPT_SALT_LENGTH; $i++) {
86 } elseif ($this->hash ==
"crypt/sha-256") {
88 for ($i = 0; $i < 16; $i++) {
92 } elseif ($this->hash ==
"crypt/sha-512") {
94 for ($i = 0; $i < 16; $i++) {
100 return '{CRYPT}'.($locked ?
'!' :
'').crypt($pwd, $salt);
103 function checkPassword ($pwd, $hash):
bool 115 if (CRYPT_STD_DES == 1) {
116 $hashes[] =
"crypt/standard-des";
119 if (CRYPT_EXT_DES == 1) {
120 $hashes[] =
"crypt/enhanced-des";
123 if (CRYPT_MD5 == 1) {
124 $hashes[] =
"crypt/md5";
127 if (CRYPT_BLOWFISH == 1) {
128 $hashes[] =
"crypt/blowfish";
131 if (CRYPT_SHA256 == 1) {
132 $hashes[] =
"crypt/sha-256";
135 if (CRYPT_SHA512 == 1) {
136 $hashes[] =
"crypt/sha-512";
151 if (!preg_match(
'/^{crypt}/i', $password_hash)) {
155 $password_hash = preg_replace(
'/^{[^}]+}!?/',
'', $password_hash);
157 if (preg_match(
"/^[a-zA-Z0-9.\/][a-zA-Z0-9.\/]/", $password_hash)) {
158 return "crypt/standard-des";
161 if (preg_match(
"/^_[a-zA-Z0-9.\/]/", $password_hash)) {
162 return "crypt/enhanced-des";
165 if (preg_match(
'/^\$1\$/', $password_hash)) {
169 if (preg_match(
'/^(\$2\$|\$2a\$)/', $password_hash)) {
170 return "crypt/blowfish";
173 if (preg_match(
'/^\$5\$/', $password_hash)) {
174 return "crypt/sha-256";
177 if (preg_match(
'/^\$6\$/', $password_hash)) {
178 return "crypt/sha-512";
get_random_char()
Returns a random char.
This class contains all the functions for crypt password methods.
generate_hash(string $pwd, bool $locked=FALSE)
Generate template hash.
__construct()
passwordMethodCrypt Constructor
static get_hash_name()
Get the hash name.
is_available()
Is available.
This class contains all the basic function for password methods.
static _extract_method($password_hash)
Extract a method.