take Robert S. code and go 1 step further and do a hash on it, like <@assign name="request$hashCode" value='<@CIPHER ACTION="hash" TYPE="MD5" STR="@@code">'>
you can play around with different has ciphers On Oct 14, 2010, at 11:01 AM, Roland Dumas wrote: > This looks good. THank you. Going to test it out. Was thinking > currenttimestamp could make it unique, but converting it to non-obvious > random-looking code was stumping me. thanks. > > On Oct 14, 2010, at 10:53 AM, Robert Shubert wrote: > >> Try this out: >> >> <@! start with epoch> >> <@ASSIGN secs <@TSTOSECS <@CURRENTTIMESTAMP>>> >> >> <@! add salt> >> <@ASSIGN secs "<@RANDOM low=1 high=9>@@secs<@RANDOM low=1 high=9>"> >> >> <@! convert to base 26> >> <@WHILE expr="@@secs > 26"> >> >> <@! shift to ascii for capitals 65-90 convert to char and build code> >> <@IF "<@CURROW>%2 = 0"> >> <@ASSIGN code '<@CHAR <@CALC "abs(@@secs % 26) + 65">>@@code'> >> <@ELSE> >> <@ASSIGN code '@@code<@CHAR <@CALC "abs(@@secs % 26) + 65">>'> >> </@IF> >> >> <@! shift place for base conversion> >> <@ASSIGN secs <@CALC "@@secs / 26" precision=0>> >> >> </@WHILE> >> >> Final Code: @@code >> >> DISCLAIMER: It is possible to create the same code if this routine is run >> multiple times in the same second. Add a <@SLEEP 1000> to prevent this. >> Also, there is an abs() in there because doing modulo on large values >> produces a negative value. This is incorrect behavior on Witango's part and >> something that I'll need to fix in the server. I do not think it produces a >> collision problem in this routine, but it may. It is likely tied to small >> floating point variable used in the routine. Oh, and there is also a >> rounding error that I didn't work out, but again, it only changed some shift >> points (26^1 place increases at unit=13 rather than unit=0). This can >> removed by floor()ing the base conversion shift in the final @CALC. Again, I >> do not believe that this causes a collision situation. Also, this routine >> can occasionally create a 7 character code. You may need to check for and >> ignore these if you want them all to 8 characters (This may be able to be >> eliminated by increasing the LOW value in the first @RANDOM) Lastly, I don't >> guarantee this routine. I just whipped it up as a mental exercise, so you >> may want to test it out some (see if you get a collision over a few million >> iterations), or show it to someone who is good with algorithms or >> cryptography. >> >> Robert >> >> -----Original Message----- >> From: Roland Dumas [mailto:[email protected]] >> Sent: Thursday, October 14, 2010 11:42 AM >> To: [email protected] >> Subject: Witango-Talk: generating unique codes >> >> >> looking for method to create unique and non-obvious n-digit codes to be used >> as discount codes. >> Should be short enough to use as consumer codes (8 digit?), and probably be >> something simply to enter, such as an all caps, and not have an easily >> discoverable pattern. >> >> I want to generate unique codes and not have to check the history to see if >> a code has been used before. >> >> Suggestions? >> >> >> >> >> >> ---------------------------------------- >> >> To unsubscribe from this list, please send an email to [email protected] >> with "unsubscribe witango-talk" in the body. >> >> >> >> ---------------------------------------- >> >> To unsubscribe from this list, please send an email to [email protected] >> with "unsubscribe witango-talk" in the body. >> > > > > ---------------------------------------- > > To unsubscribe from this list, please send an email to [email protected] > with "unsubscribe witango-talk" in the body. > > Ben Johansen http://www.webspinr.com [email protected] Phone: 360-597-3372 Mobile: 360-600-7775 ---------------------------------------- To unsubscribe from this list, please send an email to [email protected] with "unsubscribe witango-talk" in the body.
