]> granicus.if.org Git - php/commitdiff
Actually complete password_create()
authorAnthony Ferrara <ircmaxell@ircmaxell.com>
Mon, 25 Jun 2012 03:25:18 +0000 (23:25 -0400)
committerAnthony Ferrara <ircmaxell@ircmaxell.com>
Mon, 25 Jun 2012 03:25:18 +0000 (23:25 -0400)
ext/standard/password.c
ext/standard/php_password.h

index 677f1325caa2a3744d3e1f3f669155342a2050a3..9201ff3f8d1fed2260d2526b5038f56243242bfd 100644 (file)
@@ -28,7 +28,7 @@
 #include "php_password.h"
 #include "php_rand.h"
 #include "base64.h"
-
+#include "zend_interfaces.h"
 
 PHP_MINIT_FUNCTION(password) /* {{{ */
 {
@@ -139,15 +139,20 @@ PHP_FUNCTION(password_make_salt)
 Hash a password */
 PHP_FUNCTION(password_create)
 {
-        char *password, *algo = 0, *hash_format, *hash, *salt;
-        int password_len, algo_len = 0, salt_len = 0, required_salt_len = 0, hash_format_len;
+        char *algo = 0, *hash_format, *hash, *salt;
+        int algo_len = 0, salt_len = 0, required_salt_len = 0, hash_format_len;
         HashTable *options = 0;
-        zval **option_buffer;
+        zval **option_buffer, *ret, *password, *hash_zval;
 
-        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sH", &password, &password_len, &algo, &algo_len, &options) == FAILURE) {
+        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|sH", &password, &algo, &algo_len, &options) == FAILURE) {
                 RETURN_FALSE;
         }
 
+       if (Z_TYPE_P(password) != IS_STRING) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Password must be a string");
+               RETURN_FALSE;
+       }
+
         if (algo_len == 0) {
                algo = PHP_PASSWORD_DEFAULT;
                 algo_len = strlen(PHP_PASSWORD_DEFAULT);
@@ -240,10 +245,26 @@ PHP_FUNCTION(password_create)
        hash = emalloc(salt_len + hash_format_len + 1);
        sprintf(hash, "%s%s", hash_format, salt);
        hash[hash_format_len + salt_len] = 0;
+
+       ALLOC_INIT_ZVAL(hash_zval);
+       ZVAL_STRINGL(hash_zval, hash, hash_format_len + salt_len, 0);
+
        efree(hash_format);
        efree(salt);
 
-        RETURN_STRINGL(hash, hash_format_len + salt_len, 0);
+       zend_call_method_with_2_params(NULL, NULL, NULL, "crypt", &ret, password, hash_zval);
+
+       zval_ptr_dtor(&hash_zval);
+
+       if (Z_TYPE_P(ret) != IS_STRING) {
+               zval_ptr_dtor(&ret);
+               RETURN_FALSE;
+       } else if(Z_STRLEN_P(ret) < 13) {
+               zval_ptr_dtor(&ret);
+               RETURN_FALSE;
+       }
+
+       RETURN_ZVAL(ret, 0, 1);
 }
 /* }}} */
 
index f813189a46be170c16000b7c17c2a21ae1953734..5967840d51dae363b6138cfae9779822439c4b32 100644 (file)
@@ -33,7 +33,7 @@ PHP_MINIT_FUNCTION(password);
 #define PHP_PASSWORD_SHA256    "5"
 #define PHP_PASSWORD_SHA512    "6"
 
-#define PHP_PASSWORD_BCRYPT_DEFAULT_COST 14;
+#define PHP_PASSWORD_BCRYPT_DEFAULT_COST 12;
 #define PHP_PASSWORD_SHA_DEFAULT_ROUNDS 5000;