Re: Generate a unique ID that identifies the client?



On Jun 16, 8:46 am, iryndin <iryn...@xxxxxxxxx> wrote:
On Jun 15, 11:34 pm, stec00 <steve.chamb...@xxxxxxxxx> wrote:



I have an javascript application that needs to generate a unique ID
that will identify the client. It doesn't really matter what this ID
is, a number, string or even set of ascii codes would be fine - as
long as it is unique or nearly unique. The ID needs to be something
that can be worked out just from the client's info. Ideally it would
be done in straight javascript but if this isn't possible I'd even
consider an AJAX request that got the info from a server. I've got a
server that's running PHP so this would be the preferred server side
language if that option is chosen.

Anyway I'm racking my brains trying to work out how to do this. In
Javascript I've been considering whether it might be possible to use
some combination of UserAgent components but UserAgent doesn't really
provide very much that would be unique and the snag is it might change
if say the user changed their add-ons or version of Firefox etc. (We
can assume the user is running Firefox here since this is for a
GreaseMonkey script). I'd hoped there might be some way to get the
user's MAC address (it only has to be unique for the computer being
used) but it seems this isn't possible to get hold of using Javascript
or PHP. In PHP I'd considered using the IP address but this isn't
necessarily going to stay the same over time, which is another
requirement.

So I'm running into quite a few dead ends and now turning to Internet-
land for help...Can anyone think of a way? Would be grateful for any
suggestions.

Cheers,
Steve

Hello, Steve.

I think, you can use UUID (Universally Unique IDentifiers) for your
purposes. There isn't true implementation of UUID generation in
JavaScript due to sandbox issues (cannot get MAC-address of network
adapter from JavaScript), but some Javascript implementations provide
reasonable uniqueness.

You can try this link:http://af-design.com/services/javascript/uuid/
- JavaScript UUID generator is provided here under GPL License.

The other way is to ask server to generate UUIDs. I am specialized in
Java, and I know about java.util.UUID class, which provides such
functionality. Simple Java code example:

import java.util.UUID;

public class GenerateUUID {

    public static final void main(String[] args) {
        //generate random UUIDs
        UUID id1 = UUID.randomUUID();
        UUID id2 = UUID.randomUUID();
        System.out.println(id1);
        System.out.println(id2);
    }

}

you should obtain something like:
deea44c7-a180-4898-9527-58db0ed34683
596befcd-fc85-487e-9dbf-9739240d0fc7

Recently I have written a note in my blog about its usage, seehttp://jdevnotes.blogspot.com/2009/05/blog-post.html.
(The note is in Russian).

You can write a servlet which simply returns back generated UUIDs, and
you can use it in AJAX-calls to server, so that page will not be
reloaded.
I am sure that other server-side technologies (PHP, Python, Ruby,
etc..etc....) also provide similar functionality.

Regards,
Ivan Ryndin.
Java Dev Notes blog:http://jdevnotes.blogspot.com

Hi Ivan,

Thanks for taking the time to reply and your efforts. Unfortunately
from what I've seen it doesn't seem to provide what I'm looking for. I
need more than just the ability to generate unique IDs, it has to be a
unique *identifier* for a particular client that can be repeatedly
determined at any time. So I think based on that, the function that
produced it would have to know something about the client, whether it
be an IP address, MAC address, or just perhaps some combination of
things that may be unique for the client (OS, timezone etc.) But
unfortunately I haven't been able to find such a thing so far -
generating unique IDs e.g. calculated from the time or some other
randomisation method is fine but getting an identifier for a client
seems to be nigh on impossible. Perhaps it's for good reasons of
security (as PointedEars alluded to) but if so I'd like to know why,
when you look at a webpage that webpage can know and record your IP
address, which is "nearly" unique for each user - were it not for such
things as dynamic IPs, proxies etc. So this is just one step further
and wouldn't have to actually convey any sensitive information.

Cheers
Steve
.



Relevant Pages