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?
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.
for node users this package helps to generate unique id install:
npm i node-machine-id
code:
import {machineId, machineIdSync} from 'node-machine-id';
// Asyncronous call with async/await or Promise
async function getMachineId() {
let id = await machineId();
...
}
machineId().then((id) => {
...
})
// Syncronous call
let id = machineIdSync()
// id = c24b0fe51856497eebb6a2bfcd120247aac0d6334d670bb92e09a00ce8169365
let id = machineIdSync({original: true})
// id = 98912984-c4e9-5ceb-8000-03882a0485e4
You can use timestamp for a unique ID and append some static text to it:
var uniqueID = "ID-"+(new Date()).getTime().toString();
© 2022 - 2024 — McMap. All rights reserved.
fingerprintjs
for generating fingerprints, but I want to do this without this library... How can it be done? How about reading the library... or better yet, just use it? Your attempt at doing this yourself will most likely not be as good (especially since you need to ask here how it's done) – Outdate