Example #1
0
func TOTPImageHandler(w http.ResponseWriter, r *http.Request) {
	user := GetUser(r, false)
	if user == nil {
		ReturnJSON(API_UNAUTHORIZED, "Unauthorized")
	}
	label := fmt.Sprintf("FtNox-%v", user.Email)
	img, err := totp.BarcodeImage(label, user.TOTPKey, nil)
	if err != nil {
		ReturnJSON(API_ERROR, err.Error())
	}
	w.Header().Set("Content-Type", "image/png")
	w.Write(img)
}
Example #2
0
func main() {
	img, _ := totp.BarcodeImage("testing-totp", []byte("foobar"), nil)
	ioutil.WriteFile("barcode.png", img, 0777)
	fmt.Println("Barcode image written to barcode.png")
	fmt.Println("Enter your token and I will tell you whether it is right")

	in := bufio.NewReader(os.Stdin)
	input := ""

	for input != "q" {
		input, _ := in.ReadString('\n')
		input = strings.TrimRight(input, "\n")
		ok := totp.Authenticate([]byte("foobar"), input, nil)
		fmt.Println(fmt.Sprintf("%v", ok))
	}
}