Created
March 20, 2022 14:42
-
-
Save nakul5harma/377c512eba4935a027af09e034a36ae0 to your computer and use it in GitHub Desktop.
Generate cryptographically secure OTP in TypeScript/ JavaScript/ NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { randomBytes } from "crypto"; | |
export const generateCryptographicallySecureOTP = (otpLength: number) => { | |
return parseInt(randomBytes(otpLength).toString("hex"), 16) | |
.toString() | |
.substr(0, otpLength); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment