正在研究怎么不用密码限制访问权限,想到用“指纹”来验证用户身份,这里就整理一下。
只研究浏览器和客户端能获取到的“指纹”。

常见指纹

navigator.platform //系统平台
"Win32"
navigator.userAgent //UA
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"
navigator.appVersion //浏览器版本
"5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36"
navigator.cookieEnabled //cookie可用
true
navigator.cpuClass //cpu单元
undefined
navigator.hardwareConcurrency //核心数量
4
navigator.language //系统语言
"zh-CN"
window.screen //分辨率
Screen {availWidth: 1366, availHeight: 724, width: 1366, height: 768, colorDepth: 24, …}availHeight: 724availLeft: 0availTop: 0availWidth: 1366colorDepth: 24height: 768orientation: ScreenOrientation {angle: 0, type: "landscape-primary", onchange: null}pixelDepth: 24width: 1366__proto__: Screen
navigator.plugins //浏览器插件,这里太复杂不贴了

new Date().getTimezoneOffset() //时区 -480是东八区
-480
window.screen.colorDepth //颜色质量
24

获取定位

我测试失败了

var options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0
};

function success(pos) {
  var crd = pos.coords;

  console.log('Your current position is:');
  console.log('Latitude : ' + crd.latitude);
  console.log('Longitude: ' + crd.longitude);
  console.log('More or less ' + crd.accuracy + ' meters.');
};

function error(err) {
  console.warn('ERROR(' + err.code + '): ' + err.message);
};

navigator.geolocation.getCurrentPosition(success, error, options);

uuid生成

function rand(len) {
    var hex = "0123456789abcdef",
        str = "",
        index = 0;
    for (len = len || 32; len > index; index++) {
        str += hex.charAt(Math.ceil(1e8 * Math.random()) % hex.length);
    }
    return str;
}

var uuid = (new Date).getTime() + "_" + rand();

canvas指纹

function bin2hex(s) {
  var i, l, o = '',
    n;

  s += '';

  for (i = 0, l = s.length; i < l; i++) {
    n = s.charCodeAt(i)
      .toString(16);
    o += n.length < 2 ? '0' + n : n;
  }

  return o;
}

function getUUID(domain) {
    var canvas = document.createElement('canvas');
    var ctx = canvas.getContext("2d");
    var txt = domain;
    ctx.textBaseline = "top";
    ctx.font = "14px 'Arial'";
    ctx.textBaseline = "tencent";
    ctx.fillStyle = "#f60";
    ctx.fillRect(125,1,62,20);
    ctx.fillStyle = "#069";
    ctx.fillText(txt, 2, 15);
    ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
    ctx.fillText(txt, 4, 17);

    var b64 = canvas.toDataURL().replace("data:image/png;base64,","");
    var bin = atob(b64);
    var crc = bin2hex(bin.slice(-16,-12));
    return crc;
}

console.log(getUUID("https://www.baidu.com/"));

源码

https://github.com/Song-Li/cross_browser
https://github.com/Valve/fingerprintjs2

指纹识别库

https://cdnjs.com/libraries/fingerprintjs2
https://cdn.jsdelivr.net/npm/fingerprintjs2@2.0.6/dist/fingerprint2.min.js
https://cdnjs.cloudflare.com/ajax/libs/fingerprintjs2/2.0.6/fingerprint2.js
https://cdnjs.cloudflare.com/ajax/libs/fingerprintjs2/2.0.6/fingerprint2.min.js

查看自己的指纹

https://amiunique.org/fp
https://audiofingerprint.openwpm.com/
https://browserprint.info/view
http://uniquemachine.org/ 这个很牛逼可以跨浏览器识别指纹

相关资料

http://uniquemachine.org/
https://browserprint.info/
2.5代指纹追踪技术—跨浏览器指纹识别

最后修改:2019 年 02 月 22 日
如果觉得我的文章对你有用,请随意赞赏