Created
October 20, 2017 13:28
-
-
Save uilian/dba9a646ddb9ba6b82de50f59815ab91 to your computer and use it in GitHub Desktop.
Generate browser unique fingerprint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script | |
src="https://code.jquery.com/jquery-3.2.1.min.js" | |
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" | |
crossorigin="anonymous"></script> | |
<script | |
src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js" ></script> | |
<script type="text/javascript"> | |
/* Generate a fingerprint string for the browser */ | |
function generateFingerprint(){ | |
console.log('teste'); | |
//Generate a string based on "stable" information taken from the browser | |
//We call here "stable information", information that normally don't change during the user | |
//browse the application just after authentication | |
var fingerprint = []; | |
//Take plugins | |
for(var i = 0; i < navigator.plugins.length; i++){ | |
fingerprint.push(navigator.plugins[i].name); | |
fingerprint.push(navigator.plugins[i].filename); | |
fingerprint.push(navigator.plugins[i].description); | |
fingerprint.push(navigator.plugins[i].version); | |
} | |
//Take User Agent | |
fingerprint.push(navigator.userAgent); | |
//Take Screen resolution | |
fingerprint.push(screen.availHeight); | |
fingerprint.push(screen.availWidth); | |
fingerprint.push(screen.colorDepth); | |
fingerprint.push(screen.height); | |
fingerprint.push(screen.pixelDepth); | |
fingerprint.push(screen.width); | |
//Take Graphical card info | |
//See http://output.jsbin.com/ovekor/3/ | |
try { | |
//Add a Canvas element if the body do not contains one | |
if ( $("#glcanvas").length == 0 ){ | |
$(document.body).append("<canvas id='glcanvas'></canvas>"); | |
} | |
//Get ref on Canvas | |
var canvas = document.getElementById("glcanvas"); | |
//Retrieve Canvas properties | |
gl = canvas.getContext("experimental-webgl"); | |
gl.viewportWidth = canvas.width; | |
gl.viewportHeight = canvas.height; | |
fingerprint.push(gl.getParameter(gl.VERSION)); | |
fingerprint.push(gl.getParameter(gl.SHADING_LANGUAGE_VERSION)); | |
fingerprint.push(gl.getParameter(gl.VENDOR)); | |
fingerprint.push(gl.getParameter(gl.RENDERER)); | |
fingerprint.push(gl.getSupportedExtensions().join()); | |
} catch (e) { | |
//Get also error because it's will be stable too.. | |
fingerprint.push(e); | |
} | |
//Last and, in order to made this browser unique, generate a random ID that we will store | |
//in local storage (in order to be persistent after browser close/reopen) | |
//Add this ID because, in Enterprise, most of the time browser have the same configuration | |
var browserUniqueID = localStorage.getItem("browserUniqueID"); | |
if (browserUniqueID === null) { | |
localStorage.setItem("browserUniqueID", CryptoJS.lib.WordArray.random(80)); | |
browserUniqueID = localStorage.getItem("browserUniqueID"); | |
} | |
fingerprint.push(browserUniqueID); | |
//return fingerprint.join(); | |
console.log(fingerprint.join()); | |
}; | |
$(document).ready( function () { | |
generateFingerprint(); | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment