一种生成动态口令的方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一种生成动态口令的方法相关的知识,希望对你有一定的参考价值。
'use strict' let MD5 = require('blueimp-md5'); let UUIDv1 = require('uuid/v1'); const T = 30; let secret = 'cae99b50-c9cf-11e7-869b-9f9630b0f6a1'; //UUIDv1(); let timestamp = parseInt(Date.now() / 1000, 10); timestamp = timestamp - timestamp % T; let digest = MD5(timestamp.toString() + secret.toString()).toLowerCase(); let w = [ Buffer.from(digest.substr(0, 5)), Buffer.from(digest.substr(5, 5)), Buffer.from(digest.substr(10, 5)), Buffer.from(digest.substr(15, 5)), Buffer.from(digest.substr(20, 5)), Buffer.from(digest.substr(25, 7)) ]; let code = '';for (let i =0; i < w.length; i++) { let sum = 0; for (let j = 0; j < w[i].length; j++) { sum += w[i][j]; } code += (sum % 10).toString(); } console.log(code);以上是关于一种生成动态口令的方法的主要内容,如果未能解决你的问题,请参考以下文章