Skip to content

Commit 62cabb1

Browse files
authored
core: migrate notp to otpauth (#1157)
1 parent bbcaa61 commit 62cabb1

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

packages/hydrooj/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"mongodb-uri": "^0.9.7",
4545
"nanoid": "^5.1.11",
4646
"nodemailer": "^8.0.7",
47-
"notp": "^2.0.3",
47+
"otpauth": "^9.5.1",
4848
"p-queue": "^9.2.0",
4949
"sanitize-filename": "^1.6.4",
5050
"schemastery": "^3.18.0",
@@ -53,7 +53,6 @@
5353
"superagent": "^10.3.0",
5454
"superagent-proxy": "^3.0.0",
5555
"tar": "6.2.1",
56-
"thirty-two": "^1.0.2",
5756
"ua-parser-js": "1.0.41"
5857
},
5958
"devDependencies": {
@@ -66,7 +65,6 @@
6665
"@types/mime-types": "^3.0.1",
6766
"@types/mongodb-uri": "^0.9.4",
6867
"@types/nodemailer": "^8.0.0",
69-
"@types/notp": "^2.0.5",
7068
"@types/semver": "^7.7.1",
7169
"@types/superagent": "^8.1.9",
7270
"@types/superagent-proxy": "^3.0.4",
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import notp from 'notp';
2-
import b32 from 'thirty-two';
1+
import { Secret, TOTP } from 'otpauth';
32

43
export function verifyTFA(secret: string, code?: string) {
5-
if (!code || !code.length) return null;
6-
const bin = b32.decode(secret);
7-
return notp.totp.verify(code.replace(/\W+/g, ''), bin);
4+
if (!code || !code.length) return false;
5+
const totp = new TOTP({ secret: Secret.fromBase32(secret), algorithm: 'SHA1', digits: 6, period: 30 });
6+
return totp.validate({ token: code.replace(/\W+/g, '') }) !== null;
87
}

0 commit comments

Comments
 (0)