0

I am developing a cross platform game for which I needs to generate unique identifier (User ID) for each user. I known some platform (Android or iOS) specific approaches to get device related identifiers but I am looking for a solution independent of the device identifiers.

User ID Requirements:

  1. Independent of the device's platform
  2. Offline implementation (no communication with any servers)
  3. Without sign-up process

I have implemented one approach to create User IDs where I store the system time when the game was launched for the first time on the device.

I have following questions:

  1. Are there any other approaches to generate User IDs (which will meet the above requirements)?
  2. What are the common approaches to create unique identifiers with taking any information from the user?
  3. Are there any third party plug-ins to implement User IDs?

I would appreciate any suggestions and thoughts on this topic.

EDIT:

There are lot of responses to use UUID/GUID. Generally, this approach looks fine but I am looking for a solution which can generate same User ID even if the user reinstall the game.

5 Answers5

3

Have you looked at UUID from Java?

https://docs.oracle.com/javase/7/docs/api/java/util/UUID.html

EDIT: The following links might help using UUID for unique identifiers.

Best practices for permissions & Identifiers

Instance ID

  • Thank you for the response. Yes, I already checked this approach. I am looking for an approach which can be used for Android as well as iOS platform. – Nimesh Chandramaniya Feb 01 '18 at 13:07
  • 2
    Every platform has some form of UUIDs. @NimeshChandramaniya 's suggestion is the way to go. – Sotiris S. Magionas Feb 01 '18 at 13:09
  • Well, I'm not aware about Apple's development tools. Can't help much. :/ As last recourse, I would suggest that you implement your own "UUID class" and create methods to generate a ID based on some criterias, such as time, user name, birthday, etc... But keep in mind, that's not ideal and far away of securtity recommendations. – Ulysses Caetano Braga Feb 01 '18 at 13:25
  • @UlyssesCaetanoBraga Sorry, I misread your suggestion. I thought your suggesting to use UDID and not UUID. I agree with your suggestion of using UUID. Can this approach survive app uninstall? – Nimesh Chandramaniya Feb 02 '18 at 04:25
  • @NimeshChandramaniya no problems at all! They can't survive the uninstall / reinstall from an app. Reading around, found this four links that I might help you. [link 1](https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id?rq=1) [link 2](https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id/2785493#2785493) [link 3](https://android-developers.googleblog.com/2011/03/identifying-app-installations.html) [link 4](https://developer.android.com/training/articles/user-data-ids.html) – Ulysses Caetano Braga Feb 07 '18 at 11:08
  • @UlyssesCaetanoBraga Thank you for the links. Those are helpful. After reading the "Best Practices For Unique Identifiers" (link 4), I think UUID will be most suitable for my use case. – Nimesh Chandramaniya Feb 08 '18 at 03:58
  • Great! Hope ur app reaches the top! – Ulysses Caetano Braga Feb 08 '18 at 10:30
1

When you say user id, are you talking about a public id such as an username, or a database id?

If you are talking about a database id, go for a GUID/UUID. T-sql for example have the NEWID() method that will return a GUID that doesn't exist in the database yet. I am sure that whichever database you go for you will find some way to use a GUID.

https://learn.microsoft.com/en-us/sql/t-sql/functions/newid-transact-sql

  • Thank you for the response. Yes, I already checked this approach. I am looking for an approach which can be used for Android as well as iOS platform. – Nimesh Chandramaniya Feb 01 '18 at 13:08
  • If you use the same database for both ios and android this will work. Just create a stored procedure which sets the id to a GUID/UUID, and takes all relevant information from your user-object as arguments. I would like to see these guidelines that apple and google have :) – Fritjof Höst Feb 01 '18 at 14:50
  • I am sure that you still can use the UUID approach, only to have it be deterministic. I did some light googling and found some people solving this. Just base it on the deviceId or something like that. https://stackoverflow.com/questions/19402327/how-to-get-unique-id-in-ios-device https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id http://blag.koveras.net/2010/12/03/how-to-generate-a-deterministic-guid-from-two-strings-in-java/ – Fritjof Höst Feb 02 '18 at 07:51
0

As per my opinion your System current time is the best method for generating Unique User Id.

For Android : System.currentTimeMillis() returns you the unique 13 digit number which can be used as User Id.

But When you get current time in iOS then it is 10 digit number which generates. So you can multiply it by 1000 to make User Id platform Independent.

Happy Coding...

Rushabh Shah
  • 680
  • 4
  • 22
  • 1
    With a huge number of users you may face with collision so you will have more than one user with same id. – Andrew Feb 01 '18 at 13:12
  • 1
    Yes it may be the case but it is very rare to happen but if User base is vast then one possible solution is that we can multiply this generated time with random number of single digit. – Rushabh Shah Feb 01 '18 at 13:19
0

Assuming that your usernames are unique, you could simply takje the md5 hash of your usernames to get an unique ID (string). e.g. in php:

$userID = md5($username);

because m5 hash functions exist in nearly every programming language you should be able to use this ID on all possible plattforms.

And if you arer looking for a numeric ID, you even can calculate a qunique number from md5.

See represent md5-hash as an integer - stack question for more details

Radon8472
  • 4,285
  • 1
  • 33
  • 41
-1

Just generate a long string of random characters. For example, generates a 10 long string of alphanumerics ...

private String GetId(){
    String[] chars = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"};
    StringBuilder s = new StringBuilder(10);

    for(int i = 0;i<10;i++){
        int pos = (int) (Math.random() * 62);
        String c = "";
        if (pos > chars.length-1){
            pos = pos - chars.length;
            c = chars[pos].toUpperCase();
        }else{
            c = chars[pos];
        }

        s.append(c);
    }

    return s.toString();
}
Mark Sheekey
  • 608
  • 7
  • 23