<?php
/*-------------------------------------------------------+
| PHPFusion Content Management System
| Copyright (C) PHP Fusion Inc
| https://phpfusion.com/
+--------------------------------------------------------+
| Filename: bltfmhu_password_generator.inc.php
| Title: Jelszó Generátor
| Version: 1.0.0
| CVS Version: 9.10.xxx
| PHP-Fusion Mods Builder
| Author: Mathias
| Web: https://fusion.bltfm.hu/
+--------------------------------------------------------+
| Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
defined('IN_FUSION') || exit;
/**
 * Password generator
 */
function password_generator($length = 12) {
	$ABC = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
	$_abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
	$num = ['0','1','2','3','4','5','6','7','8','9'];
	$spe = ['@','!','#','$','%','&','/','(',')','=','-','_','?','+','*','.',',',':',';']; // ,''
	$db_cha = $length/4;
	$cha = [];
	$cha_ = '';

	for ($i=0; $i < $db_cha; $i++) {
		shuffle($ABC);
		$rand_keys = array_rand($ABC, $db_cha);
		$cha[] = $ABC[$rand_keys[$i]];
		unset($ABC[$rand_keys[$i]]);
	}
	for ($i=0; $i < $db_cha; $i++) {
		shuffle($_abc);
		$rand_keys = array_rand($_abc, $db_cha);
		$cha[] = $_abc[$rand_keys[$i]];
		unset($_abc[$rand_keys[$i]]);
	}
	for ($i=0; $i < $db_cha; $i++) {
		shuffle($num);
		$rand_keys = array_rand($num, $db_cha);
		$cha[] = $num[$rand_keys[$i]];
		unset($num[$rand_keys[$i]]);
	}
	for ($i=0; $i < $db_cha; $i++) {
		shuffle($spe);
		$rand_keys = array_rand($spe, $db_cha);
		$cha[] = $spe[$rand_keys[$i]];
		unset($spe[$rand_keys[$i]]);
	}
	shuffle($cha);
	shuffle($cha);
	foreach($cha as $key => $val) {
		$cha_ .= $val;
	}
	return $cha_;
}

function xpassword_generator() {
	$result = [];
	$result['result'] = 'valid';
	$result['response'] = password_generator(12);
	header('Content-Type: application/json');
	echo json_encode($result);
}

/**
 * @uses xpassword_generator()
 */
fusion_add_hook('fusion_filters', 'xpassword_generator');