Hi.
In the registration interface the registrant can generate a strong password for himself.
Currently 12 character password is generated.
- Two lowercase letters
- Two uppercase
- Two number
- Two symbols
To use this mode, you need to modify three core files and create one new file.
Editing
/includes/api/index.php
Look for this
$endpoints = [
"username-check" => "username_validation.php",
"userpass-check" => "userpass_validation.php",
'calling-codes' => 'calling_codes.php', //get
'geomap-states' => 'states.php', //get
Change
$endpoints = [
"username-check" => "username_validation.php",
"userpass-check" => "userpass_validation.php",
'calling-codes' => 'calling_codes.php', // get
'geomap-states' => 'states.php', // get
'password-recommender' => 'bltfmhu_password_generator.inc.php'
Create a new file here
/includes/api/
The name of the file
bltfmhu_password_generator.inc.php
Contents
<?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');
Editing
/includes/classes/PHPFusion/UserFields.php
Look for this
$this->info['user_password'] .= form_text('user_password1', $locale['u134a'], '', [
'type' => 'password',
'autocomplete_off' => 1,
'inline' => TRUE,
'max_length' => 64,
'error_text' => $locale['u134'].$locale['u143a'],
'required' => !$this->admin_mode,
'ext_tip' => $locale['u147']
]
);
Change
$this->info['user_password'] .= form_text('user_password1', $locale['u134a'], '', [
'type' => 'password',
'autocomplete_off' => 1,
'inline' => TRUE,
'max_length' => 64,
'error_text' => $locale['u134'].$locale['u143a'],
'required' => !$this->admin_mode,
'ext_tip' => $locale['u147']."<div style='padding-top: 2px;'><button title='' id='modal_pwdgen' name='modal_pwdgen' type='button' value='".$locale['pwdgen00']."' class='btn btn-primary' style='padding: 5px;'>".$locale['pwdgen00']."</button></div>"
]
);
/* BltFMHU MOD _PASSWORD_GENERATOR */
echo openmodal('pwdgen_modal', $locale['pwdgen00'], ['button_id' => 'modal_pwdgen']);
echo form_text('pwd_inp', $locale['pwdgen01'], '',
['type' => 'text', 'inline' => TRUE, 'max_length' => 64, 'deactivate' => TRUE, 'append_button' => TRUE, 'append_value' => $locale['pwdgen02'], 'append_button_id' => 'cp_btn', 'append_form_value' => $locale['pwdgen02'], 'append_button_name' => 'cp_btn', 'append_class' => 'btn btn-default', 'append_type' => 'button']
);
echo form_checkbox('copy_check', $locale['pwdgen03'], '0', ['type' => 'checkbox', 'required' => TRUE, 'toggle' => FALSE, 'class' => 'row-center']);
echo modalfooter("
<div style='position: absolute;left:0;bottom: 0;padding: 5px;'>
<a href='https://fusion.bltfm.hu/' title='".$locale['pwdgen05']."' >'window.open(this.href); return false;' onkeypress='window.open(this.href); return false;'><span>".$locale['pwdgen06']."</span></a></div>"
.form_button('pwd_copy', $locale['pwdgen04'], 'pwd_copy', ['deactivate' => TRUE, 'type' => 'button', 'class' => 'btn-default']),
TRUE
);
add_to_jquery("
$.ajax({
url: '".INCLUDES."api/?api=password-recommender',
method: 'POST',
data: '',
dataType: 'json',
success: function (e) {
$('#pwd_inp').val(e.response);
}
});
$('#modal_pwdgen').click(function () {
if ($('#copy_check').is(':checked')) {
$('#copy_check').prop('checked', false);
$('#pwd_copy').addClass('disabled');
$('#pwd_copy').attr('disabled', true);
$.ajax({
url: '".INCLUDES."api/?api=password-recommender',
method: 'POST',
data: '',
dataType: 'json',
success: function (e) {
$('#pwd_inp').val(e.response);
}
});
}
});
$('input[type=checkbox]').bind('click', function () {
if ($(this).is(':checked')) {
$('#pwd_copy').removeClass('disabled');
$('#pwd_copy').removeAttr('disabled');
} else {
$('#pwd_copy').addClass('disabled');
$('#pwd_copy').attr('disabled', true);
}
});
$('#cp_btn').click(function () {
$.ajax({
url: '".INCLUDES."api/?api=password-recommender',
method: 'POST',
data: '',
dataType: 'json',
success: function (e) {
$('#pwd_inp').val(e.response);
}
});
});
");
add_to_jquery('
function copyToClipboard(text) {
var textArea = document.createElement("textarea");
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
var successful = document.execCommand("copy");
var msg = successful ? "successful" : "unsuccessful";
console.log("Copying text command was " + msg);
} catch (err) {
console.log("Oops, unable to copy", err);
}
document.body.removeChild(textArea);
}
$("#pwd_copy").click( function() {
var clipboardText = "";
clipboardText = $("#pwd_inp").val();
copyToClipboard(clipboardText);
$("#pwdgen_modal-Modal").modal("toggle");
$("#user_password1").val(clipboardText);
$("#user_password2").val(clipboardText);
});
');
echo closemodal();
/* BltFMHU MOD _PASSWORD_GENERATOR END */
Editing
/locale/English/user_fields.php
Copy this to the end of the file
/* BltFMHU MOD _PASSWORD_GENERATOR */
$locale['pwdgen00'] = "Password generator";
$locale['pwdgen01'] = 'Suggested password';
$locale['pwdgen02'] = "Password generation";
$locale['pwdgen03'] = "You have copied this password to a safe place!";
$locale['pwdgen04'] = "Use a password";
$locale['pwdgen05'] = "v.1.0.0 Fusion.BltFm.hu";
$locale['pwdgen06'] = "v.1.0.0 by ".utf8_encode('đ');
/* BltFMHU MOD _PASSWORD_GENERATOR END */
You're done, use it