Log in |
A random password generatorNeed a quick and dirty one-time psuedo-random key for user registration via email passwords or similar ? Here's one way. :
<dtml-var standard_html_header>
<dtml-let s="_.string.letters + _.string.digits">
<dtml-call "REQUEST.set('k1',_.whrandom.choice(s))">
<dtml-in "_.range(_.whrandom.choice([4,5,6]))">
<dtml-call "REQUEST.set('k1',k1 + _.whrandom.choice(s))">
</dtml-in>
your one time key is <dtml-var k1>
</dtml-let>
<dtml-var standard_html_footer>
This snippet illustrates the use of a dtml loop combined with access to some inbuilt python utilities like the string module constants. letters and digits. It will return a key of 5,6 or 7 characters - longer or shorter keys can be generated by adjusting the range - variable length adds to the difficulty of guessing the key. Note that the Wichmann-Hill generator which is built in to the python interpreter has a relatively short period compared to some other pseudo-random generators. The seed for this generator is set using the system time at the instant the module is first imported, so if anyone can find out what that was, they could theoretically figure out the sequence of outputs from this code - in which case all bets are off ! However, for many purposes this will make a pretty secure (ie hard to guess) onetime key. |