Thread subject: Official Home of the PHPFusion CMS :: Password generator mod

Posted by MathiasHU on 20-12-2021 16:31
#1

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
Code
$endpoints = [
 "username-check" => "username_validation.php",
 "userpass-check" => "userpass_validation.php",
 'calling-codes' => 'calling_codes.php', //get
 'geomap-states' => 'states.php', //get


Change
Code
$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
Code
<?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'wink || 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 = ['@','!','#','$','%','&','/','(','wink','=','-','_','?','+','*','.',',',':',';']; // ,''
   $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]]wink;
   }
   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]]wink;
   }
   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]]wink;
   }
   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]]wink;
   }
   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'wink;
   echo json_encode($result);
}

/**
 * @uses xpassword_generator()
 */
fusion_add_hook('fusion_filters', 'xpassword_generator'wink;



Editing
/includes/classes/PHPFusion/UserFields.php

Look for this
Code
$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']
 ]
 wink;


Change
Code
$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>"
 ]
 wink;
/* BltFMHU MOD _PASSWORD_GENERATOR */
echo openmodal('pwdgen_modal', $locale['pwdgen00'], ['button_id' => 'modal_pwdgen']wink;

   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']
   wink;

   echo form_checkbox('copy_check', $locale['pwdgen03'], '0', ['type' => 'checkbox', 'required' => TRUE, 'toggle' => FALSE, 'class' => 'row-center']wink;

   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']wink,
      TRUE
   wink;

   add_to_jquery("
      $.ajax({
         url: '".INCLUDES."api/?api=password-recommender',
         method: 'POST',
         data: '',
         dataType: 'json',
         success: function (e) {
            $('#pwd_inp'wink.val(e.response);
         }
      });
      $('#modal_pwdgen'wink.click(function () {
         if ($('#copy_check'wink.is(':checked'wink) {
            $('#copy_check'wink.prop('checked', false);
            $('#pwd_copy'wink.addClass('disabled'wink;
            $('#pwd_copy'wink.attr('disabled', true);
            $.ajax({
               url: '".INCLUDES."api/?api=password-recommender',
               method: 'POST',
               data: '',
               dataType: 'json',
               success: function (e) {
                  $('#pwd_inp'wink.val(e.response);
               }
            });
         }
      });
      $('input[type=checkbox]'wink.bind('click', function () {
         if ($(this).is(':checked'wink) {
            $('#pwd_copy'wink.removeClass('disabled'wink;
            $('#pwd_copy'wink.removeAttr('disabled'wink;
         } else {
            $('#pwd_copy'wink.addClass('disabled'wink;
            $('#pwd_copy'wink.attr('disabled', true);
         }
      });
      $('#cp_btn'wink.click(function () {
         $.ajax({
            url: '".INCLUDES."api/?api=password-recommender',
            method: 'POST',
            data: '',
            dataType: 'json',
            success: function (e) {
               $('#pwd_inp'wink.val(e.response);
            }
         });
      });
   "wink;
   add_to_jquery('
      function copyToClipboard(text) {
         var textArea = document.createElement("textarea"wink;
         textArea.value = text;
         document.body.appendChild(textArea);
         textArea.select();
         try {
            var successful = document.execCommand("copy"wink;
            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"wink.click( function() {
         var clipboardText = "";
         clipboardText = $("#pwd_inp"wink.val();
         copyToClipboard(clipboardText);
         $("#pwdgen_modal-Modal"wink.modal("toggle"wink;
         $("#user_password1"wink.val(clipboardText);
         $("#user_password2"wink.val(clipboardText);
      });
   'wink;

echo closemodal();
/* BltFMHU MOD _PASSWORD_GENERATOR END */



Editing
/locale/English/user_fields.php

Copy this to the end of the file
Code
/* 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('đ'wink;
/* BltFMHU MOD _PASSWORD_GENERATOR END */



You're done, use it

Edited by MathiasHU on 11-07-2026 13:53

Posted by RobiNN on 21-12-2021 03:29
#2

Something like this was added in v10. But it can be added directly to the form_text() function, so it can be used anywhere.

Posted by MathiasHU on 21-12-2021 16:27
#3

I have not seen v10

Posted by RobiNN on 21-12-2021 16:59
#4

This version is not released and will take several years to develop. Btw. code is in a private repo, so only core developers have access to it. But well so far only Fred added things into it.

Edited by RobiNN on 11-07-2026 13:53

Posted by MathiasHU on 21-12-2021 18:41
#5

I understand, then I use my own code

Maybe you could get into a later Fusion version if you like the idea.

Edited by MathiasHU on 21-12-2021 23:12

Posted by RobiNN on 23-12-2021 00:30
#6

Password generator is not bad idea, but I would add it directly to form_text(). Perhaps it will be in the next v9 update.

Edited by RobiNN on 11-07-2026 13:53

Posted by MathiasHU on 23-12-2021 22:34
#7

All right.

Posted by MathiasHU on 22-03-2022 23:48
#8

I have added it directly to form_text()
Test in progress

Edited by MathiasHU on 24-03-2022 23:19

Posted by MathiasHU on 26-03-2022 21:50
#9

Hi.

In the registration interface the registrant can generate a strong password for himself.

Currently 16 character password is generated.
- Four lowercase letters
- Four uppercase
- Four number
- Four symbols

To use this mode, you need to modify three core files and create one new file.

Tested v9.10.20
Editing
/includes/api/index.php

Look for this
Code
$endpoints = [
 "username-check" => "username_validation.php",
 "userpass-check" => "userpass_validation.php",
 'calling-codes' => 'calling_codes.php', //get
 'geomap-states' => 'states.php', //get


Change
Code
$endpoints = [
 "username-check" => "username_validation.php",
 "userpass-check" => "userpass_validation.php",
 'calling-codes' => 'calling_codes.php', // get
 'geomap-states' => 'states.php', // get
 'password-recommender' => 'password_generator.inc.php'


Create a new file here
/includes/api/

The name of the file
password_generator.inc.php

Contents
Code
<?php
/*-------------------------------------------------------+
| PHPFusion Content Management System
| Copyright (C) PHP Fusion Inc
| https://phpfusion.com/
+--------------------------------------------------------+
| Filename: password_generator.inc.php
| Title: Password generator
| Version: 1.1.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'wink || exit;
/**
 * Password generator
 */
function password_generator($length = 16) {
   $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 = ['@','!','#','$','%','&','/','(','wink','=','-','_','?','+','*','.',',',':',';'];
   $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]]wink;
   }
   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]]wink;
   }
   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]]wink;
   }
   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]]wink;
   }
   shuffle($cha);
   shuffle($cha);
   foreach($cha as $key => $val) {
      $cha_ .= $val;
   }
   return $cha_;
}

function xpassword_generator() {
   $result = [];
   //$result['result'] = 'invalid';
   $result['result'] = 'valid';
   $result['response'] = password_generator(16);
   header('Content-Type: application/json'wink;
   echo json_encode($result);
}

/**
 * @uses xpassword_generator()
 */
fusion_add_hook('fusion_filters', 'xpassword_generator'wink;



Editing
/includes/dynamics/includes/form_text.php

Look for this
Code
'mask_options' => [],


Change
Code
'mask_options' => [],
         'password_recommend' => TRUE


Look for this
Code
if (!empty($options['data']wink) {


Change
Code
if ($options['input_id'] == 'user_password1'wink {
      $options['data'] = ['toggle'=>'tooltip'];
   }
if ($options['input_id'] == 'user_admin_password1'wink {
      $options['data'] = ['toggle'=>'atooltip'];
   }
 if (!empty($options['data']wink) {


Look for this
Code
$html .= "</span>n";

 } else if ($options['append_value']wink {


Change
Code
if ($options['password_recommend'] == TRUE) {
 if ($options['input_id'] == 'user_password1' || $options['input_id'] == 'user_admin_password1'wink {
 $html .= "<button id='".$options['input_id']."_pwdGenerator' name='".$options['input_id']."_pwdGenerator' type='button' value='".$locale['pwdgen00']."' class='btn btn-default'>".$locale['pwdgen00']."</button>";
            add_to_jquery("$('#".$options['input_id']."_pwdGenerator'wink.on('click', function(e) {
                  $.ajax({
                     url: '".INCLUDES."api/?api=password-recommender',
                     method: 'POST',
                     data: '',
                     dataType: 'json',
                     success: function (e) {
                        if (".$options['input_id']." == user_password1) {
                           $('#user_password1'wink.val(e.response);
                           $('#user_password2'wink.val(e.response);
                           $('#user_password1'wink.attr('title', '".$locale['pwdgen01']."'wink;
                           $('[data-toggle="tooltip"]'wink.tooltip('show'wink;
                           $('#user_password1-field'wink.addClass('has-success'wink;
                           $('#user_password1'wink.addClass('is-valid'wink;
                        } else
                        if (".$options['input_id']." == user_admin_password1) {
                           $('#user_admin_password1'wink.val(e.response);
                           $('#user_admin_password2'wink.val(e.response);
                           $('#user_admin_password1'wink.attr('title', '".$locale['pwdgen01']."'wink;
                           $('[data-toggle="atooltip"]'wink.tooltip('show'wink;
                           $('#user_admin_password1-field'wink.addClass('has-success'wink;
                           $('#user_admin_password1'wink.addClass('is-valid'wink;
                        }
                     }
                  });
               });
            "wink;
 }
 }
 $html .= "</span>n";

 } else if ($options['append_value']wink {


Editing
/locale/English/user_fields.php

Copy this to the end of the file
Code
/* BltFMHU MOD _PASSWORD_GENERATOR */
$locale['pwdgen00'] = "Password Generator";
$locale['pwdgen01'] = "Copy the password to a safe place!";
/* BltFMHU MOD _PASSWORD_GENERATOR END */

Edited by MathiasHU on 27-03-2022 00:15

Posted by MathiasHU on 25-10-2022 22:10
#10

Hi there.
I developed the mod again, it will be available soon if anyone is interested.

By clicking on the input field, you will be offered to generate a password.
There is also a setting option on the password generation interface. The setting option will be expanded a little further in the future.

Posted by douwe_yntema on 26-10-2022 07:55
#11

same:


https://www.php-fusion.co.uk/infusions/forum/viewthread.php?thread_id=40166&highlight=password+generate&pid=208552#post_208552

Posted by MathiasHU on 26-10-2022 21:44
#12

Hi, the code I wrote is completely different.
The mode can also be useful during the registration and profile editing interface. Look, open the registration interface and start filling in the fields or just the password field

https://fusion.bltfm.hu/register.php

Posted by MathiasHU on 01-11-2022 23:20
#13

Sample

i.postimg.cc/Y40VxHyw/password-generator-sample-1.png


i.postimg.cc/mcnnX501/password-generator-sample-2.png


Soon ...

Posted by MathiasHU on 02-11-2022 12:37
#14

Language file is waiting for verification. Someone?

Posted by helmuth on 05-11-2022 11:43
#15

Danish locales attached ;-)

Posted by helmuth on 05-11-2022 11:49
#16

js file attached