Page Blocks

Hosting sponsored by:

Point In Space

 

API: Str

Filename:
fwpStr_randomPswd.ctag

Released With:
5.0.0

Current Version:
1.0.0

Status: Active

Min Lasso Tested: 8.1.0

Max Lasso Tested: 8.5.3

Related:

Still don't get it?

Check out the talk list archives, or join and ask your questions.

Documentation Error or Request?

Email documentation corrections or comments

API Reference

fwpStr_randomPswd (Tag)

Description

Creates a text string of random characters of n length comprised of upper and lower case letters, numerals, and symbols. Letters o, O, i, I, and the numeral 0 are omitted.

The resulting string will always have 1 uppercase letter, 1 lowercase letter, 1 numeral, and 1 of symbols of the set (!@#$%^*). Thus the minimum returned string length is 4.

Compared to fwpStr_randomID, this tag creates strings better suited to passwords. Use it to assign a user a password for temporary or permanent use.

Syntax

[fwpStr_randomPswd: integer>4]

Parameters & Member Tags

length (unnamed) - required : an integer > 4 specifying the length of the string.

Examples

[fwpStr_randomPswd: 8]

Source Code

View in separate window

<?lassoscript
//............................................................................
//
//    pageblocks: (c) 2002-2007 http://www.pageblocks.org/
//
//............................................................................
/*

    {fileName=        fwpStr_randomPswd.ctag }
    {rsrcType=        tag }
    {rsrcName=        fwpStr_randomPswd }
    {rsrcHTTP=        www.pageblocks.org/refc/fwpStr_randomPswd }

    {lassoVrsnMin=    8.1.0 }
    {lassoVrsnMax=    8.5.3 }

    {author=        Greg Willits }
    {authorEmail=    subscribe to pbTalk at www.pageblocks.org/talk/ }
    {authorHTTP=    www.pageblocks.org }

    {desc=            Generates a random string of characters of a specified 
                    length including one symbol char. Intended to create
                    temporary passwords. }

    {maintvsrn=        1.0 }
    {maintrelease=    5.0.0 }
    {maintdate=        2006-01-16 }
    {maintauthor=    Greg Willits }
    {maintnotes=    initial release }

*/
//.............................................................................

define_tag:'fwpStr_randomPswd', -priority='replace',
    -required='pwLen';

    if: #pwLen < 6;
        #pwLen = 6;
    /if;

    local:
        'pwVal'            = (string),
        'srcUppers'        = 'ABCDEFGHJKLMNPQRSTUVWXYZ',
        'srcLowers'        = 'abcdefghjklmnpqrstuvwxyz',
        'srcNumbers'    = '123456789',
        'srcSymbols'    = '!@#$%^*',
        'srcMixed'        = 'AaBb9CcDd8EeFf7GgHh6iJj5KkLMm4NnoPp3QqRr2SsTt1UuVv9WwXx8YyZz';

    local:
        'uprLen'    = #srcUppers->size,
        'lwrLen'    = #srcLowers->size,
        'numLen'    = #srcNumbers->size,
        'symLen'    = #srcSymbols->size,
        'mixLen'    = #srcMixed->size;

// force 4 of the characters to be consumed by these minimum requirements

    #pwVal += #srcUppers->(substring:(math_random: -min=1, -max=#uprLen),1);
    #pwVal += #srcLowers->(substring:(math_random: -min=1, -max=#lwrLen),1);
    #pwVal += #srcNumbers->(substring:(math_random: -min=1, -max=#numLen),1);
    #pwVal += #srcSymbols->(substring:(math_random: -min=1, -max=#symLen),1);

    loop: #pwLen - 4;
        #pwVal = (string_insert:
            #pwVal,
            -position=(math_random: -min=1, -max=(#pwVal->size) + 1),
            -text=#srcMixed->(substring:(math_random: -min=1, -max=#mixLen),1));
    /loop;
    
    return: #pwVal;

/define_tag;
?>

© 2002-2012, pageblocks.org