dgryski / dgoogauth Goto Github PK
View Code? Open in Web Editor NEWGoogle Authenticator for Go
Google Authenticator for Go
I would like to include this library in one of my side projects but I don't want to violate your rights. Could you please update this repository with a LICENSE file so people understand the restrictions on its use?
See: https://opensource.org/licenses
Google has a very useful document which discusses its legal positions on each of the open source licenses as far as being consumed for commercial purposes. It's a good way to understand the consequences of certain licenses such as the WTFPL: https://opensource.google.com/docs/thirdparty/licenses/
In readme.md RTC 6238
should probably be RFC 6238
.
Thanks for a very useful library.
The following function sometimes returns 5 digits instead of 6:
Lines 27 to 49 in 96977cb
e.g.
package main
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base32"
"encoding/binary"
"fmt"
"time"
"github.com/dgryski/dgoogauth"
)
func main() {
secret := []byte{'H', 'e', 'l', 'l', 'o', '!', 0xDE, 0xAD, 0xBE, 0xEF}
secretEnc := base32.StdEncoding.EncodeToString(secret)
var t0 int64
t0 = int64(time.Now().Unix() / 2)
code := dgoogauth.ComputeCode(secretEnc, t0)
fmt.Printf("code = %+v\n", code)
}
func ComputeCode(secret string, value int64) int {
key, err := base32.StdEncoding.DecodeString(secret)
if err != nil {
return -1
}
hash := hmac.New(sha1.New, key)
err = binary.Write(hash, binary.BigEndian, value)
if err != nil {
return -1
}
h := hash.Sum(nil)
offset := h[19] & 0x0f
truncated := binary.BigEndian.Uint32(h[offset : offset+4])
truncated &= 0x7fffffff
code := truncated % 1000000
return int(code)
}
Outputs the following when looped:
code = 292234
code = 108363
code = 108363
code = 828914
code = 45510
code = 45510
code = 45288
code = 45288
code = 286406
code = 166336
code = 166336
code = 569768
code = 569768
I received this error when decoding my 26 character secret.
You should probably update your code to decode the secret using this: gokyle/twofactor#10 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.