1. main package : https://github.com/xlzd/gotp
package main
import (
"fmt"
"time"
"github.com/xlzd/gotp"
)
func main() {
totp := gotp.NewDefaultTOTP("4S62BZNFXXSZLCRO") // ini cara create paling simple
// klo mau custom bs pake gotp.NewTOTP(secret, 6, 30, nil) secret=string, 6=digits, 30=interval in second
code := totp.Now()
mytime := int(30 - time.Now().Unix()%30)
unixtime := int(time.Now().Unix())
fmt.Println("pertama : ", totp.Verify(code, mytime), mytime)
fmt.Println("kedua : ", totp.Verify(code, unixtime), unixtime)
fmt.Println("bedanya : ", totp.Verify(code, unixtime+28))
time.Sleep(8 * time.Second)
unixtime = int(time.Now().Unix())
fmt.Println("kedua : ", totp.Verify(code, unixtime), unixtime)
//myjeda := int(90 - time.Now().Unix()%90)
newcode := totp.At(unixtime + 90) // akan hidup pd jam sekarang + 90 detik (sebelum waktu itu di anggap false), dan jangka hidupnya tetep 30 detik
// time.Sleep(33 * time.Second)
fmt.Println("ketiga : ", totp.Verify(newcode, unixtime+30))
fmt.Println("keempat : ", totp.Verify(newcode, unixtime+60))
fmt.Println("kelima : ", totp.Verify(newcode, unixtime+91))
fmt.Println("keenam : ", totp.Verify(newcode, unixtime+100))
fmt.Println("ketujuh : ", totp.Verify(newcode, unixtime+121))
}
-------------
pertama : false 30
kedua : true 1257894000
bedanya : true
kedua : true 1257894008
ketiga : false
keempat : false
kelima : true
keenam : true
ketujuh : false
Program exited.
..show all:.
.
1. main package : https://github.com/xlzd/gotp
package main
import (
"fmt"
"time"
"github.com/xlzd/gotp"
)
func main() {
totp := gotp.NewDefaultTOTP("4S62BZNFXXSZLCRO") // ini cara create paling simple
// klo mau custom bs pake gotp.NewTOTP(secret, 6, 30, nil) secret=string, 6=digits, 30=interval in second
code := totp.Now()
mytime := int(30 - time.Now().Unix()%30)
unixtime := int(time.Now().Unix())
fmt.Println("pertama : ", totp.Verify(code, mytime), mytime)
fmt.Println("kedua : ", totp.Verify(code, unixtime), unixtime)
fmt.Println("bedanya : ", totp.Verify(code, unixtime+28))
time.Sleep(8 * time.Second)
unixtime = int(time.Now().Unix())
fmt.Println("kedua : ", totp.Verify(code, unixtime), unixtime)
//myjeda := int(90 - time.Now().Unix()%90)
newcode := totp.At(unixtime + 90) // akan hidup pd jam sekarang + 90 detik (sebelum waktu itu di anggap false), dan jangka hidupnya tetep 30 detik
// time.Sleep(33 * time.Second)
fmt.Println("ketiga : ", totp.Verify(newcode, unixtime+30))
fmt.Println("keempat : ", totp.Verify(newcode, unixtime+60))
fmt.Println("kelima : ", totp.Verify(newcode, unixtime+91))
fmt.Println("keenam : ", totp.Verify(newcode, unixtime+100))
fmt.Println("ketujuh : ", totp.Verify(newcode, unixtime+121))
}
-------------
pertama : false 30
kedua : true 1257894000
bedanya : true
kedua : true 1257894008
ketiga : false
keempat : false
kelima : true
keenam : true
ketujuh : false
Program exited.
No comments:
Post a Comment