PHP code example of outofoffice / password-generator

1. Go to this page and download the library: Download outofoffice/password-generator 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/ */

    

outofoffice / password-generator example snippets


// in app/Nova/[Resource].php

use OutOfOffice\PasswordGenerator\PasswordGenerator;

public function fields()
{
    return [

        PasswordGenerator::make( 'Password' )
            ->onlyOnForms()
            ->creationRules( '

// in app/Nova/[Resource].php

use OutOfOffice\PasswordGenerator\PasswordGenerator;

public function fields()
{
    return [

        PasswordGenerator::make( 'Password' )
            // Password length, not respecting prefix or suffix length
            ->length( int $length = 16 )
            // Overrides general length, respects prefix or suffix length
            ->totalLength( int $length = 24 )
            // Generated passwords will be minimum of this value
            ->minLength( int $minLength = 8 )
            // Generated passwords will be maximum of this value
            ->maxLength( int $maxLength = 128 )
            // Length should increment by this value when changing length via field
            ->lengthIncrementSteps( int $lengthSteps = 4 ),

    ];
}

// in app/Nova/[Resource].php

use OutOfOffice\PasswordGenerator\PasswordGenerator;

public function fields()
{
    return [

        PasswordGenerator::make( 'Password' )
            // Generated passwords will start with this value (e.g. 'ooo.jX90')
            ->prefix( 'ooo.' ) // default: ''
            // Generated passwords will end with this value (e.g. 'jX90.ooo')
            ->suffix( '.ooo' ), // default: ''

    ];
}

// in app/Nova/[Resource].php

use OutOfOffice\PasswordGenerator\PasswordGenerator;

public function fields()
{
    return [

        PasswordGenerator::make( 'Password' )
            // Hide all toolbar elements, or combo this method with other
            // methods to display only one or two elements
            ->hideAllExtras( bool $hide = true )
            // Hide the show password button from the toolbar, or don't
            ->hideShowPasswordToggle( bool $hide = true )
            // Hide the password generation options from the toolbar, or don't
            ->hideOptionsToggles( bool $hide = true )
            // Hide the password length input from the toolbar, or don't
            ->hideLengthInput( bool $hide = true )
            // Hide the copy password button from the toolbar, or don't
            ->hideCopyPasswordButton( bool $hide = true )
            // Hide the refresh/regenerate password button from the toolbar, or don't
            ->hideRegenerateButton( bool $hide = true ),

    ];
}

// in app/Nova/[Resource].php

use OutOfOffice\PasswordGenerator\PasswordGenerator;

public function fields()
{
    return [

        PasswordGenerator::make( 'Password' )
            // Included by default, you can exclude all uppercase characters (e.g. ABC)
            ->excludeUppercase( bool $exclude = true )
            // Included by default, you can exclude all lowercase characters (e.g. abc)
            ->excludeLowercase( bool $exclude = true )
            // Included by default, you can exclude all numbers characters (e.g. 123)
            ->excludeNumbers( bool $exclude = true )
            // Included by default, you can exclude all symbols characters (e.g. $@!)
            ->excludeSymbols( bool $exclude = true )
            // Excluded by default, you can exclude characters that may look similar
            // (e.g. "i, l, 1, L, o, 0, O")
            ->excludeSimilar( bool $exclude = true )
            // Excluded by default, you can exclude ambiguous symbols
            // (e.g. "{ } [ ] ( ) / \ ' " ` ~ , ; : . < >")
            ->excludeAmbiguous( bool $exclude = true )
            // One method to exclude multiple options, accepts the following:
            // 'uppercase' or 'upper', 'lowercase' or 'lower', 'numbers' or 'digits',
            // 'symbols' or 'special', 'similar', 'ambiguous'
            ->excludeRules( array $excludeRules )
            // Customize the character list for the generated password, just pass
            // a string to this method, check PasswordGenerator class for more charlists
            // using this method auto-hides the option element from the toolbar
            ->customCharlist( string $charlist = PasswordGenerator::BASE16_MOD ),

    ];
}

// in app/Nova/[Resource].php

use OutOfOffice\PasswordGenerator\PasswordGenerator;

public function fields()
{
    return [

        PasswordGenerator::make( 'Password' )
            // Disabled by default, will fill input with generated password on load
            // only when creating a new resource.
            ->fillOnCreate( bool $enabled = true )
            // Disabled by default, will fill input with generated password on load
            // only when updating a new resource.
            ->fillOnUpdate( bool $enabled = true ),

    ];
}

// in app/Nova/[Resource].php

use OutOfOffice\PasswordGenerator\PasswordGenerator;

public function fields()
{
    return [

        PasswordGenerator::make( 'Personal Access Token' )
            // Show the password as plain-text by default on the respective pages
            // These three methods work well with the others as they just show the field value
            // on page load, you can use the other methods below for the styling
            ->showValueOnDetail( bool $show = true )
            ->showValueOnIndex( bool $show = true )
            ->showValueOnUpdate( bool $show = true )
            // Hide the password with a blur effect on the respective pages
            ->blurValueOnDetail( bool $show = true )
            ->blurValueOnIndex( bool $show = true )
            // Hide the password with a set character on the respective pages
            ->redactValueOnDetail( bool $redact = true, string $character = '•' )
            ->redactValueOnIndex( bool $redact = true, string $character = '•' )

    ];
}

// in app/Nova/[Resource].php

use OutOfOffice\PasswordGenerator\PasswordGenerator;

public function fields()
{
    return [

        PasswordGenerator::make( 'Password' )
            // Show the password as plain-text in the password field by default
            ->showPassword( bool $show = true )
            // Should the password be regenerated when an option is changed
            ->regenerateOnToggle( bool $enabled = true )
            // Should the toolbar be placed above the password field
            ->toolbarOnTop( bool $toolbarOnTop = true )
            // Disable the side toolbar, only displaying it above or below the password field
            ->disableSideToolbar( bool $disable = true )
            // Disable hashing the field value while saving to the database
            // Always hash your users passwords! This is for other non-sensitive use-cases
            ->saveAsPlainText( bool $plainText = true ),

    ];
}

php artisan vendor:publish --provider="OutOfOffice\PasswordGenerator\FieldServiceProvider"