How to create a email OTP

Im trying to make a email otp, so when a user signs up or logs in they get a OTP.
and to make a 2FA as well.

How can i make it work on a free plan?

anyone?