Solved

Engine to generate random alphanumeric characters 4 DB

Posted on 2001-07-25
11
258 Views
Last Modified: 2012-05-04
I need an engine that will randomly produce up to 10 alphanumeric characters later to be stored in a table of my SQL2000 db. Here's a run down on how I plan to use it:

I have a SQL2000 database web site that will have the ability to use CDONTS to send email. Within this email that gets sent will be 3 session variables and one URL. The url will return the person who gets the email to a 'hidden' record within the database that points to some information about the email sender. I paln on appending values to the url to make it complete.

So in the email you'd see:

http://www.mywebsite.com/information?abcdef1234.asp

The http://www.mywebsite.com/information? is something I have in the message body of the email with the value abcdef1234 added to it.


When you click on it, your taken to web page abcdef1234.asp and you can see the data stored on that page.

This value (abcdef1234) should first get set in the table when a user creates an account for the first time. So for example:

Account:

Username, password, first name, and a hidden account code of abcdef1234 was generated when the person click the submit button...

The user doesn't see the hidden number, but is a session value, that I carry when the user logs in, and later clicks to apply on line.

I need this info to be unique, and random. If its not random, then any user could enter abcdef1235 and find the next users info.

Maybe someone could point me to a site that has something or if this is simple (and I?m making it too hard) to do in ASP, please let me know. Examples are certainly welcome. J

I?m opening this question at 125 points and depending how hard it becomes, I?ll adjust the points as we go.



Thanks

Jim
0
Comment
Question by:JPersinger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6318239
function createRandomPassword()
     dim x,y,z
     randomize
     z=""
     for x = 1 to 10
          y=0
          while (y < 65 or (y > 90 and y < 97) OR (y > 122))
               y = round(rnd() * 122)
          Wend
          z = z & chr(y)
     next 'x          
     set x = Nothing
     set y = Nothing
     createRandomPassword = z
     set z = Nothing
end function
0
 

Expert Comment

by:cscheepers
ID: 6318275
I would suggest not to use random values but rather use something that uses the date and time (timestamps).

To do this use the following:

<%UniqueKey = Date & Time
%>

But since this will be a filename, you would maybe like to remove all unwanted characters, as well as spaces:

<%UniqueKey = Replace(UniqueKey, "/", "")
  UniqueKey = Replace(UniqueKey, "\", "")
  UniqueKey = Replace(UniqueKey, ":", "")
  UniqueKey = Replace(UniqueKey, " ", "")

  ... 'Whatever other might occur

  UniqueKey = UniqueKey & ".asp"
%>

You can even use the IP Address together with the timestamp to create a more unique key.  Just remember to remove all unwanted characters (".").

<%Request.ServerVariables("Remote_Addr")%>

I hope this helps.  Let me know
0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 6318289
What if two people subscribe at the same time?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 28

Expert Comment

by:AzraSound
ID: 6318290
you want it to be unique too correct?  just create a GUID (globally unique identifier).  it is longer than 10 characters but it is gauranteed to be unique always:


<%
guid = server.createobject("scriptlet.typelib").guid
response.write guid
%>


the variable 'guid' can be used as your custom/unique/random value
0
 

Author Comment

by:JPersinger
ID: 6318303
WOW - You people are GREAT!!!!!!!!!!!!!!!!

I like the idea of the GUID...Let me try that and see how far I get...


Jim
0
 
LVL 7

Expert Comment

by:John844
ID: 6318309
why not use the sessionID value
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6318337
i'm not positive, but under the covers, i believe the Session object creates its ID value using a GUID.  also, if you create your own GUID manually, there is no worries of users with cookies disabled.
0
 

Author Comment

by:JPersinger
ID: 6319242
The GUID seems to work good so far. Two quick questions:

1) Is there a way to remove the {} and
2) Is there a way to remove the - (dashes) in between the numbers before it posts to the DB?

Increased points to 135.

Thanks
Jim
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 135 total points
ID: 6319284
sure, after creating the GUID, you can eliminate those extra characters:

<%
guid = server.createobject("scriptlet.typelib").guid
guid = Replace(guid, "{", "")
guid = Replace(guid, "}", "")
guid = Replace(guid, "-", "")

'Update DB with guid
%>

0
 

Author Comment

by:JPersinger
ID: 6319294
EXCELLENT WORK!

Jim
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6319351
glad i could help   :-)
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question