com php-src: Implement password_get_info() function : ext/standard/basic_functions.c ext/standard/passwor d.c ext/standard/php_password.h
| From: | Anthony Ferrara | Date: | Thu, 05 Jul 2012 21:46:33 +0000 |
| Subject: | com php-src: Implement password_get_info() function : ext/standard/basic_functions.c ext/standard/passwor d.c ext/standard/php_password.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-70371@lists.php.net to get a copy of this message | ||
Commit: ee7e7998410c8fd5bd2183b1af375622f0ca8e02
Author: Anthony Ferrara <ircmaxell@gmail.com> Thu, 5 Jul 2012 17:46:33 -0400
Parents: db86d54446c461eab518225645889abc509db034
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ee7e7998410c8fd5bd2183b1af375622f0ca8e02
Log:
Implement password_get_info() function
Changed paths:
M ext/standard/basic_functions.c
M ext/standard/password.c
M ext/standard/php_password.h
Diff:
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index bf6f9b0..e6500dd 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 6da656c..9be6f8c 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 45e6849..90e4d89 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);