PHP code example of pdir / key-generator-bundle

1. Go to this page and download the library: Download pdir/key-generator-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pdir / key-generator-bundle example snippets



$GLOBALS['TL_DCA']['tl_member']['fields']['apikey'] = array
(
  'label'         => &$GLOBALS['TL_LANG']['tl_member']['apikey'],
	'exclude'       => true,
	'search'        => false,
	'inputType'     => 'text',
	'wizard'		=> [['\Pdir\KeyGeneratorBundle\KeyGenerator','getWizard']],
	'save_callback'	=> [['\Pdir\KeyGeneratorBundle\KeyGenerator','setKeyIfEmpty']],
	'eval'          => ['maxlength'=>32, 'feEditable'=>false, 'feViewable'=>false, 'feGroup'=>'rpc', 'tl_class'=>'w50 wizard'],
	'sql'           => "varchar(32) NOT NULL default ''"
);



// config.php
$GLOBALS['TL_HOOKS']['generateKey'][] = array('\MyClass','generateKey');

// MyClass
public function generateKey($strFieldName, $intLength)
{
  if ($strFieldName == 'simplePasswordField')
  {
    return str_repeat('X',$intLength);
  }
  else if ($strFieldName == 'megaPasswordField')
  {
    return 'pasword123';
  }
  return false;
}