ZEND_ARG_INFO(0, password)
ZEND_ARG_INFO(0, hash)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_password_make_salt, 0, 0, 1)
- ZEND_ARG_INFO(0, length)
- ZEND_ARG_INFO(0, raw_output)
-ZEND_END_ARG_INFO()
/* }}} */
/* {{{ proc_open.c */
#ifdef PHP_CAN_SUPPORT_PROC_OPEN
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)
-
PHP_FE(convert_uuencode, arginfo_convert_uuencode)
PHP_FE(convert_uudecode, arginfo_convert_uudecode)
REGISTER_LONG_CONSTANT("PASSWORD_DEFAULT", PHP_PASSWORD_DEFAULT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PASSWORD_BCRYPT", PHP_PASSWORD_BCRYPT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("PASSWORD_SALT_RAW", PHP_PASSWORD_SALT_RAW, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("PASSWORD_SALT_BCRYPT", PHP_PASSWORD_SALT_BCRYPT, CONST_CS | CONST_PERSISTENT);
-
return SUCCESS;
}
/* }}} */
}
/* }}} */
-#define PHP_PASSWORD_FUNCTION_EXISTS(func, func_len) (zend_hash_find(EG(function_table), (func), (func_len) + 1, (void **) &func_ptr) == SUCCESS && func_ptr->type == ZEND_INTERNAL_FUNCTION && func_ptr->internal_function.handler != zif_display_disabled_function)
-
static int php_password_make_salt(long length, int salt_type, char *ret TSRMLS_DC) /* {{{ */
{
int buffer_valid = 0;
}
/* }}} */
-/* {{{ proto string password_make_salt(int length, int salt_type = PASSWORD_SALT_BCRYPT)
-Make a new random salt */
-PHP_FUNCTION(password_make_salt)
-{
- char *salt;
- long length = 0, salt_type = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &length, &salt_type) == FAILURE) {
- RETURN_NULL();
- }
- if (length <= 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length cannot be less than or equal zero: %ld", length);
- RETURN_NULL();
- } else if (length > (LONG_MAX / 3)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length is too large to safely generate");
- RETURN_NULL();
- }
-
- if (!salt_type) {
- salt_type = PHP_PASSWORD_SALT_BCRYPT;
- }
- salt = safe_emalloc(length, 1, 1);
- if (php_password_make_salt(length, (int) salt_type, salt TSRMLS_CC) == FAILURE) {
- efree(salt);
- RETURN_FALSE;
- }
- RETURN_STRINGL(salt, length, 0);
-}
-/* }}} */
-
/* {{{ proto string password_hash(string password, int algo, array options = array())
Hash a password */
PHP_FUNCTION(password_hash)
PHP_FUNCTION(password_hash);
PHP_FUNCTION(password_verify);
-PHP_FUNCTION(password_make_salt);
PHP_FUNCTION(password_needs_rehash);
PHP_FUNCTION(password_get_info);
+++ /dev/null
---TEST--
-Test normal operation of password_make_salt()
---FILE--
-<?php
-//-=-=-=-
-echo strlen(password_make_salt(1)) . "\n";
-echo strlen(password_make_salt(2)) . "\n";
-echo strlen(password_make_salt(3)) . "\n";
-echo strlen(password_make_salt(4)) . "\n";
-echo strlen(password_make_salt(5, PASSWORD_SALT_BCRYPT)) . "\n";
-echo "\n";
-
-echo strlen(password_make_salt(1, PASSWORD_SALT_RAW)) . "\n";
-echo strlen(password_make_salt(2, PASSWORD_SALT_RAW)) . "\n";
-echo strlen(password_make_salt(3, PASSWORD_SALT_RAW)) . "\n";
-echo strlen(password_make_salt(4, PASSWORD_SALT_RAW)) . "\n";
-echo strlen(password_make_salt(5, PASSWORD_SALT_RAW)) . "\n";
-echo "\n";
-
-$a = password_make_salt(32);
-$b = password_make_salt(32);
-
-var_dump($a != $b);
-echo "OK!";
-?>
---EXPECT--
-1
-2
-3
-4
-5
-
-1
-2
-3
-4
-5
-
-bool(true)
-OK!
+++ /dev/null
---TEST--
-Test error operation of password_make_salt()
---FILE--
-<?php
-//-=-=-=-
-
-var_dump(password_make_salt());
-
-var_dump(password_make_salt("foo"));
-
-var_dump(password_make_salt(-1));
-
-var_dump(password_make_salt(PHP_INT_MAX));
-
-var_dump(password_make_salt(floor(PHP_INT_MAX / 2.9)));
-
-var_dump(password_make_salt(5, 999));
-
-?>
---EXPECTF--
-Warning: password_make_salt() expects at least 1 parameter, 0 given in %s on line %d
-NULL
-
-Warning: password_make_salt() expects parameter 1 to be long, string given in %s on line %d
-NULL
-
-Warning: password_make_salt(): Length cannot be less than or equal zero: -1 in %s on line %d
-NULL
-
-Warning: password_make_salt(): Length is too large to safely generate in %s on line %d
-NULL
-
-Warning: password_make_salt(): Length is too large to safely generate in %s on line %d
-NULL
-
-Warning: password_make_salt(): Unknown salt type paramter in %s on line %d
-bool(false)