Unique Identifier for Online Application

I am writing an online application where I need to make sure everyone applying gets a unique identifier.  Right now I am using the date and time but I am not comfortable with it.  Right now two people could potentially grab the same number.  

I've read where people recommend ID & Token, but do not know how to implement.  Could someone give me some simple logic for this?  Thanks for helping.  I am using CF7.

What I am using now:
<cfset todaydate = DateFormat(now(), "yyyymmdd")>
<cfset todaytime = TimeFormat(now(), "hhmmss")>
<cfset UniqueNO = '#todaydate##todaytime#'>
Who is Participating?
dgrafxConnect With a Mentor Commented:
<cfset UniqueNO = CreateUUID()>
Guaranteed to be unique!
You could also just use the database.  When you said "everyone applying..." makes me think there will be a database record of the transaction.

The primary key of the table would be unique.

create table applicants (
   applicant_id    int    identity(1,1)   not null

sulzenerAuthor Commented:
Okay, both suggestions work.  dgrafx (#1), answered the question and gdemaria (#2) got me thinking a different direction.   Let me ask a little deeper question.
I like #1 because I didn't plan to write the record until the very end.
I like #2 because the number is smaller and I want to use it for a couple things.

1) The user is attaching two files to the application.  I am using the application no. as part of the file name.
2)  Also, I'd like to use the number as a tracking number for status lookup capabilities.  #1 creates a huge number.  #2 could be a little small.

Does this peek any additional reseponses?
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

gdemariaConnect With a Mentor Commented:

 Don't know how you're doing your application, but the right answer may be "both" methods.

 Once the record is created in the database, I would definately want to be referring to related files and child tables using the primary key of the table and have files and child tables use a foreign key to point to it.

 However, until the user has gone far enough to create the database record, you need to keep track of his information.  This can be done using session variables, form field variables and the session ID that dgrafx mentioned can be a substitute for the primary key prior to its initial insert.

 But I'm curious?   If you're not saving the data into a table yet, why do you need a unique identifier at all ?    What does the unique ID point to exactly?    Typically, if I am collecting information the user is providing, prior to their final  "save" button being pressed, I would do one of two things...

1)  save the data in the tables anyway, just have a status flag indicating that its "work in progress".   This allows them to return later and finish or take up after a crashed browser.   If the user doesn't finish, you just sweep through and clean up all the records the unfinished status that are X days old.

2) use client, session, form variables or cookies to maintain the database until its time to save the information into the database.  Which variabel depends on how much data there is and what hoops you have to jump through to get it.

So, I'm curious how you're doing it and what the session ID will be used for?

sulzenerAuthor Commented:
Phase 1 of the project was to collect the info, email it.  Didn't need to save it.  The unique number was used to basically name the uploaded PDF files, hold them for emailing purposes only.
In Phase 2, I need to write data to a db, build a tracking portal for internal and external users. The external user will see status only.  The internal user will see everything.  
I am now working on Phase 2.  I like your suggestion of "work in progess" and even using both methods.  
hello ...
After reading the posts since I posted
it looks like you have 2 different needs.
for a unique ID in the db I'd definately go with the identity column in db
but your pdf naming may be a different thing
can each user get more than one pdf?
if so - then you can't use the one identity columns value to name several pdfs
so i guess my opinion would go something like this
<cfset UniqueNO = CreateUUID()>
<cfquery ... name="newUser">
insert into tableusers
('#UniqueNo#', '#Email#', '#whatever#')

Select Needed Columns
From tableusers
where UserID = @@Identity <!--- UserID is your identity column --->

then your code to write your pdf ....
use your UniqueNo to name it

then your code to email the pdf to this user
<cfmail ... query="NewUser">
Hello ... Here is some spam and a malicious macro from us
<CFMAILPARAM FILE = "#directorypath_to_your_pdf_dir#\#UniqueNo#.pdf"><!--- add a if fileExists probably --->      

good luck ...
sulzenerAuthor Commented:
Thank you both for your comments.  They were excellent.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.