You might want to add the extra checks for username length, error handling, etc.
This works with the file located in the root directory. Adjust it as needed.
This works with the file located in the root directory. Adjust it as needed.
Code:
<?phpdefine('IN_PHPBB', true);$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';$phpEx = substr(strrchr(__FILE__, '.'), 1);require($phpbb_root_path . 'common.' . $phpEx);require($phpbb_root_path . 'includes/functions_user.' . $phpEx);require($phpbb_root_path . 'includes/functions_module.' . $phpEx);global $config;global $phpbb_container;global $user;$timezone = $config['board_timezone'];//User data$data = array( 'username'=> 'UserTest1', 'new_password'=> '1234567', 'password_confirm'=> '1234567', 'email'=> 'test@test.com', 'group_id' => 2, 'lang'=> 'en', 'tz'=> $timezone,);$user_type = USER_NORMAL;$user_actkey = strtolower(gen_rand_string(32));$user_inactive_reason = 0;$user_inactive_time = 0;// Instantiate passwords manager/* @var $passwords_manager \phpbb\passwords\manager */$passwords_manager = $phpbb_container->get('passwords.manager');$user_row = array( 'username'=> $data['username'], 'user_password'=> $passwords_manager->hash($data['new_password']), 'user_email'=> $data['email'], 'group_id'=> $data['group_id'], 'user_timezone'=> $data['tz'], 'user_lang'=> $data['lang'], 'user_type'=> $user_type, 'user_actkey'=> $user_actkey, 'user_actkey_expiration'=> $user::get_token_expiration(), 'user_ip'=> $user->ip, 'user_regdate'=> time(), 'user_inactive_reason'=> $user_inactive_reason, 'user_inactive_time'=> $user_inactive_time,);$user_id = user_add($user_row);
Statistics: Posted by Anișor — Wed Jan 08, 2025 9:22 pm