summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Ferrara <ircmaxell@gmail.com>2012-07-05 17:46:33 -0400
committerAnthony Ferrara <ircmaxell@gmail.com>2012-07-05 17:46:33 -0400
commitee7e7998410c8fd5bd2183b1af375622f0ca8e02 (patch)
tree1b3a77b6690d0c130497fe3dd2f0ca4ead720df3
parentdb86d54446c461eab518225645889abc509db034 (diff)
downloadphp-git-ee7e7998410c8fd5bd2183b1af375622f0ca8e02.tar.gz
Implement password_get_info() function
-rw-r--r--ext/standard/basic_functions.c4
-rw-r--r--ext/standard/password.c32
-rw-r--r--ext/standard/php_password.h1
3 files changed, 37 insertions, 0 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index bf6f9b0b58..e6500dd66b 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -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)
diff --git a/ext/standard/password.c b/ext/standard/password.c
index 6da656c5af..9be6f8c366 100644
--- a/ext/standard/password.c
+++ b/ext/standard/password.c
@@ -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;
diff --git a/ext/standard/php_password.h b/ext/standard/php_password.h
index 45e6849936..90e4d89bc4 100644
--- a/ext/standard/php_password.h
+++ b/ext/standard/php_password.h
@@ -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);