Skip to content
/ tfa Public

Google Authenticator Two Factor Authentication (2FA)

Notifications You must be signed in to change notification settings

and07/tfa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2FA

Google Authenticator Two Factor Authentication (2FA)

##USE


func get2FaQR(email, issuer string) (string, string, error) {
	otp := TFA{
		Account: email,
		Issuer:  issuer,
	}

	qrBase64, err := otp.QrBase64()
	if err != nil {
		log.Printf("\x1b[31;1mWARNING: qrBytes\x1b[0m")
		return qrBase64, "", err
	}

	return qrBase64, otp.Secret, nil
}


func get2FaValid(email, issuer, token  string) error {

	otp := TFA{Account: email, Issuer: issuer}
	v, erro := otp.Validate(token)
	if erro != nil {
		return erro
	}
	if !v {
		return errors.New("error validate")
	}
	return nil
}


//OR

type Example struct{
    ...
    tfa *TFA
    ...
}

func NewExample(email, issuer string) *Example{
  	otp := TFA{
		Account: email,
		Issuer:  issuer,
	}  

    return &Example{
        tfa : &otp
    }
}

func (e *Example) TfaQR() (string, string, error) {
	qrBase64, err := e.tfa.QrBase64()
	if err != nil {
		log.Printf("\x1b[31;1mWARNING: qrBytes\x1b[0m")
		return qrBase64, "", err
	}

	return qrBase64, e.tfa.Secret, nil
}


func (e *Example) TfaValid(token  string) error {
	v, erro := e.tfa.Validate(token)
	if erro != nil {
		return erro
	}
	if !v {
		return errors.New("error validate")
	}
	return nil
}


About

Google Authenticator Two Factor Authentication (2FA)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages