I want to generate a unique id for each device. Currently I am using fingerprint.js for this. My code is:
var fingerprint = new Fingerprint().get();
But I want to generate unique id with out using any plugins. Can any one help me please?
Friends,
At last I found the answer. This code will generate unique id for each device(in a browser) all the time. But this Id will also generate a new id if the application is opened in different browser but in same device. uid
is the generated unique id.
var navigator_info = window.navigator;
var screen_info = window.screen;
var uid = navigator_info.mimeTypes.length;
uid += navigator_info.userAgent.replace(/\D+/g, '');
uid += navigator_info.plugins.length;
uid += screen_info.height || '';
uid += screen_info.width || '';
uid += screen_info.pixelDepth || '';
console.log(uid);
Thank you all for supporting me.
For example like this:
function generateUUID(){
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x3|0x8)).toString(16);
});
return uuid;
};
More on the topic: Create GUID / UUID in JavaScript?
Edit: In your comment you say, you want to generate the same id per device at any time. For such tasks, building hashes is a way to go. Get any property / properties of your device, which are unique for this device (whatever it is, it is difficult to say without example). Than build a hash out of them, for example:
var uniqueId = someHashFunction(device.property1 + device.property2 + ...);
There are plenty of hashing functions on the internet, as an example you can have a look at this one: http://phpjs.org/functions/md5/ This will return a unique value for given properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With