Implement password_get_info() function

This commit is contained in:
Anthony Ferrara 2012-07-05 17:46:33 -04:00
parent db86d54446
commit ee7e799841
3 changed files with 37 additions and 0 deletions

View File

@ -1872,6 +1872,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_password_hash, 0, 0, 1)
ZEND_ARG_INFO(0, algo)
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_password_get_info, 0, 0, 1)
ZEND_ARG_INFO(0, hash)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_password_needs_rehash, 0, 0, 1)
ZEND_ARG_INFO(0, hash)
ZEND_ARG_INFO(0, algo)
@ -2901,6 +2904,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */
PHP_FE(base64_encode, arginfo_base64_encode)
PHP_FE(password_hash, arginfo_password_hash)
PHP_FE(password_get_info, arginfo_password_get_info)
PHP_FE(password_needs_rehash, arginfo_password_needs_rehash)
PHP_FE(password_verify, arginfo_password_verify)
PHP_FE(password_make_salt, arginfo_password_make_salt)

View File

@ -161,6 +161,38 @@ static int php_password_make_salt(long length, int raw, char *ret TSRMLS_DC) /*
}
/* }}} */
PHP_FUNCTION(password_get_info)
{
long algo;
int hash_len;
char *hash;
zval *options;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hash, &hash_len) == FAILURE) {
RETURN_NULL();
}
ALLOC_INIT_ZVAL(options);
array_init(options);
algo = php_password_determine_algo(hash, hash_len);
switch (algo) {
case PHP_PASSWORD_BCRYPT:
{
long cost = PHP_PASSWORD_BCRYPT_COST;
sscanf(hash, "$2y$%ld$", &cost);
add_assoc_long(options, "cost", cost);
}
break;
}
array_init(return_value);
add_assoc_long(return_value, "algo", algo);
add_assoc_zval(return_value, "options", options);
}
PHP_FUNCTION(password_needs_rehash)
{
long new_algo = 0, algo = 0;

View File

@ -25,6 +25,7 @@ PHP_FUNCTION(password_hash);
PHP_FUNCTION(password_verify);
PHP_FUNCTION(password_make_salt);
PHP_FUNCTION(password_needs_rehash);
PHP_FUNCTION(password_get_info);
PHP_MINIT_FUNCTION(password);