mirror of
https://github.com/LanceGin/jsotp.git
synced 2026-04-17 00:01:31 +08:00
add: TOTP.verify function
This commit is contained in:
+14
-3
@@ -31,7 +31,7 @@ export class TOTP extends OTP {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* let totp = jsotp.TOTP('BASE32_ENCODED_SECRET');
|
* let totp = jsotp.TOTP('BASE32ENCODEDSECRET');
|
||||||
* totp.now(); // => 432143
|
* totp.now(); // => 432143
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
@@ -59,7 +59,7 @@ export class TOTP extends OTP {
|
|||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* let totp = jsotp.TOTP('BASE32_ENCODED_SECRET');
|
* let totp = jsotp.TOTP('BASE32ENCODEDSECRET');
|
||||||
* totp.now(); // => 432143
|
* totp.now(); // => 432143
|
||||||
* // Verify for current time
|
* // Verify for current time
|
||||||
* totp.verify(432143); // => true
|
* totp.verify(432143); // => true
|
||||||
@@ -68,6 +68,17 @@ export class TOTP extends OTP {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
verify(otp, time=null) {
|
verify(otp, time=null) {
|
||||||
return "TOTP.verify";
|
let otp_time;
|
||||||
|
|
||||||
|
if (null == time) {
|
||||||
|
time = new Date();
|
||||||
|
otp_time = this.now()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (otp === otp_time) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -14,7 +14,7 @@ describe('TOTP module test', function() {
|
|||||||
|
|
||||||
describe('verify() function', function() {
|
describe('verify() function', function() {
|
||||||
it("should print 'TOTP.verify'", function() {
|
it("should print 'TOTP.verify'", function() {
|
||||||
assert.equal("TOTP.verify", a.verify());
|
assert.equal(true, a.verify(a.now()));
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user