Skip to content

Instantly share code, notes, and snippets.

@ircmaxell
Created July 5, 2012 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ircmaxell/3056045 to your computer and use it in GitHub Desktop.
Save ircmaxell/3056045 to your computer and use it in GitHub Desktop.
password needs rehash problem
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