mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-29 08:09:52 +08:00
feat(core): support one time password (#9798)
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
createSign,
|
||||
createVerify,
|
||||
randomBytes,
|
||||
randomInt,
|
||||
timingSafeEqual,
|
||||
} from 'node:crypto';
|
||||
|
||||
@@ -109,6 +110,20 @@ export class CryptoHelper {
|
||||
return randomBytes(length);
|
||||
}
|
||||
|
||||
randomInt(min: number, max: number) {
|
||||
return randomInt(min, max);
|
||||
}
|
||||
|
||||
otp(length = 6) {
|
||||
let otp = '';
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
otp += this.randomInt(0, 9).toString();
|
||||
}
|
||||
|
||||
return otp;
|
||||
}
|
||||
|
||||
sha256(data: string) {
|
||||
return createHash('sha256').update(data).digest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user