mirror of
https://github.com/LanceGin/jsotp.git
synced 2026-05-24 00:00:05 +08:00
add: TOTP.now function
This commit is contained in:
+7
-1
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { OTP } from './otp';
|
import { OTP } from './otp';
|
||||||
|
import { Util } from './util';
|
||||||
|
|
||||||
export class TOTP extends OTP {
|
export class TOTP extends OTP {
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +36,12 @@ export class TOTP extends OTP {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
now() {
|
now() {
|
||||||
return "TOTP.now";
|
// get now time string
|
||||||
|
let now = Util.timecode(new Date(), this.interval);
|
||||||
|
|
||||||
|
// generate the one-time password
|
||||||
|
let digit = super.generate_otp(now);
|
||||||
|
return digit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-2
@@ -4,11 +4,11 @@ var assert = require('assert');
|
|||||||
describe('TOTP module test', function() {
|
describe('TOTP module test', function() {
|
||||||
|
|
||||||
var TOTP = totp.TOTP;
|
var TOTP = totp.TOTP;
|
||||||
var a = new TOTP("BASE32_ENCODED_SECRET");
|
var a = new TOTP("J22U6B3WIWRRBTAV");
|
||||||
|
|
||||||
describe('now() function', function() {
|
describe('now() function', function() {
|
||||||
it("should print 'TOTP.now'", function() {
|
it("should print 'TOTP.now'", function() {
|
||||||
assert.equal("TOTP.now", a.now());
|
assert.equal("string", typeof(a.now()));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user