[thelist] Cold fusion custom tags

.jeff jeff at members.evolt.org
Thu Jan 24 01:01:41 CST 2002


ted,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: ted serbinski
>
> I tried including this file in a loop, but each time it
> produced the same random password. I figured it cached
> the page and that is why. So I thought, what if I make
> a custom tag where I can send in a different seed to
> get different results.
>
> The calling part:
>  <cf_passwordGenerator todayDate=now()>
>
> The part being called:
>   <cfparam name="todayDate">
>   <cfset seed="#DatePart("w", todayDate)##DatePart("ww",
> todayDate)##DatePart("h", todayDate)#
>      #DatePart("n", todayDate)##DatePart("s", todayDate)#">
>
> [snip]
>
> The error I get is:
>   The required parameter todayDate was not provided.
>   This page uses the CFPARAM tag to declare the
>   parameter 'todayDate' as required for this template.
>   The parameter is not available.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

inside a custom tag, there's a structure called "attributes" that gives you
access to the, well, attributes of the custom tag.  so, simply preface
todayDate with "attributes." throughout your custom tag and it should work
just peachy.

word of advice though, running this custom tag inside a loop is still going
to generate the same result most likely because the seed will be the same
(not likely that the entire loop will take more than a second to run from
beginning to end).

if you're looking for a truly random string generation, check out the
CreateUUID() function.

another tip about the use of hashes.  always keep your code as hash-free as
possible.  *only* add hashes when you don't get the behavior you expect.
use your javascript string concatenation experience to know what to do.
take this line of yours as an example:

<cfset seed="#DatePart("w", todayDate)##DatePart("ww",
 todayDate)##DatePart("h", todayDate)#
 #DatePart("n", todayDate)##DatePart("s", todayDate)#">

strip the outermost double-quotes since these are all just function
references and use the ampersand (&) to concatenate the values the functions
return.  doing this, you can remove the hashes around the functions as well.

<cfset seed = DatePart("w", todayDate) &
              DatePart("ww", todayDate) &
              DatePart("h", todayDate) &
              DatePart("n", todayDate) &
              DatePart("s", todayDate)>
good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list