Created
July 5, 2012 19:56
-
-
Save ircmaxell/3056045 to your computer and use it in GitHub Desktop.
password needs rehash problem
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
PHP_FUNCTION(password_needs_rehash) | |
{ | |
int hash_len, newAlgo, algo = 0; | |
char *hash; | |
HashTable *options = 0; | |
zval **option_buffer; | |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|H", &hash, &hash_len, &newAlgo, &options) == FAILURE) { | |
RETURN_NULL(); | |
} | |
RETURN_LONG(hash_len); | |
algo = php_password_determine_algo(hash, hash_len); | |
if (algo != newAlgo) { | |
RETURN_LONG(algo); | |
} | |
switch (algo) { | |
case PHP_PASSWORD_BCRYPT: | |
{ | |
int newCost = PHP_PASSWORD_BCRYPT_COST, cost = 0; | |
if (hash_len < 60) { | |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Non well formed hash encountered"); | |
RETURN_NULL(); | |
} | |
if (options && zend_symtable_find(options, "cost", 5, (void **) &option_buffer) == SUCCESS) { | |
convert_to_long_ex(option_buffer); | |
newCost = Z_LVAL_PP(option_buffer); | |
zval_ptr_dtor(option_buffer); | |
} | |
sscanf(hash, "$2y$%d$", &cost); | |
if (cost != newCost) { | |
RETURN_TRUE; | |
} | |
} | |
break; | |
} | |
RETURN_FALSE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment