Skip to content

Keep getting "Tokens mismatch" error #23

@IvRRimum

Description

@IvRRimum

So, yeah. Validate returns Tokens mismatch. I can't seem to understand why ://

package main

import (
	//	"crypto"
	b64 "encoding/base64"
	"fmt"
	"github.com/sec51/twofactor"
)

func main() {
	// otpauth://totp/Cryptoapl:somemeails@gmail.com?secret=JEAM3MSPDPI5TLWDM4DEE4OCYDRVPSXY&issuer=Cryptoapl:karlis
	issuer := "somesite"
	//	otp, err := twofactor.NewTOTP("i1nfo@somethingstuff.com", issuer, crypto.SHA1, 8)
	//	if err != nil {
	//		fmt.Println(err)
	//		return
	//	}
	//
	//	bytes, err := otp.ToBytes()
	//	if err != nil {
	//		fmt.Println(err)
	//		return
	//	}

	//	bytesToString := string(bytes)
	//	base64EncodedBytes := b64.StdEncoding.EncodeToString([]byte(bytesToString))
	//	fmt.Println(base64EncodedBytes)

	stringOfBytes, _ := b64.StdEncoding.DecodeString("oQAAAAAAAACcALyxTRxmg1YFxKYPcgR4s/e+K/mqlC6M92BekB51Wor/tdD1Q3/pj2RxUmpNzU79P65u2Oefj+lPgHBixKvWEWwLgH22nM/zo9SCf5umOn2txUrsfJPPzQSmG1SO3HFoSFkKvMMR7brDuHn53bDTS1l5+VeoR/QGrugglt8w8jcOOaDHGxahaZM9LmhBBlubT+P7cP5ndUA=")
	stringToBytes := []byte(stringOfBytes)

	otpTwo, err := twofactor.TOTPFromBytes(stringToBytes, issuer)
	if err != nil {
		fmt.Println(err)
		return
	}

	//	fmt.Println(otp.Secret())
	fmt.Println(otpTwo.Secret())

	authCode := "911849"
	err = otpTwo.Validate(authCode)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Successful Authorisation!")
	return

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions