Link to home
Start Free TrialLog in
Avatar of sulzener
sulzenerFlag for United States of America

asked on

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#'>
ASKER CERTIFIED SOLUTION
Avatar of dgrafx
dgrafx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
   ...

Avatar of sulzener

ASKER

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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
(pdfNo,Email,whatever)
values
('#UniqueNo#', '#Email#', '#whatever#')

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

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 --->      
</cfmail>

good luck ...
Thank you both for your comments.  They were excellent.