From d57d060e5db54f781e73198f54ba709bae057678 Mon Sep 17 00:00:00 2001 From: Mark Burazin Date: Fri, 10 Apr 2015 10:03:07 +0200 Subject: [PATCH] per http://tools.ietf.org/html/rfc6238 floor function needs to be used here. --- gototp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gototp.go b/gototp.go index 1d770c2..d07ea48 100644 --- a/gototp.go +++ b/gototp.go @@ -56,7 +56,7 @@ func (totp *TOTP) Now() int32 { // will be valid in the next period (FromNow(1)). // This means that every code is therefore valid for 3 * totp.Period. func (totp *TOTP) FromNow(periods int64) int32 { - period := (time.Now().Unix() / int64(totp.Period)) + int64(periods) + period := math.Floor(time.Now().Unix() / int64(totp.Period)) + int64(periods) return totp.ForPeriod(period) }