/otp-go

A Go package to generate and validate OTP(One-Time-Password) .

Primary LanguageGo

OTP-Generator

This Go package is to generate One-Time Password for Email based Accoounts

Usage

In your development environment,
  • Install OTP-Go: go get github.com/seyiadel/otp-go/otp
  • Import and run go mod tidy
Gorm(Go object relational mapper) is being added during installation so as to create any database of your choice to save arguments/keyword arguments. Import Gormimport ("gorm.io/gorm) and gorm driver import "gorm.io/driver/sqlite" for your preferred database. Check Gorm.io driver. For Example using sqlite database and driver,

conn, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{}) if err != nil{ panic("failed to connect to database") }

Now you can call the package methods to validate and generate OTP.

otp.Generate(conn,"user@email.com", 4) as conn is the database, user@email.com is the user email, 4 is the desired otp length

otp.ValidateOTP(conn, "user@email.com", 7645)as conn is the database, user@email.com is the user email, 7645 is the token generated

Hurrayyyy!🤩🤩