Skip to content

Commit

Permalink
Update authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed Jun 17, 2024
1 parent 4688268 commit 81eabdc
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 77 deletions.
41 changes: 41 additions & 0 deletions src/authenticator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
> Developed by OpenMix: [https://openmix.org](https://openmix.org/mix-go)
## Mix Authenticator

Install

```
go get github.com/mix-go/authenticator@latest
```

Generate Secret

```go
secret := authenticator.GenerateSecret()
```

Generate Code

```go
code := authenticator.GenerateToken(secret)
```

Verify Code

```go
ok := authenticator.VerifyToken(secret, code)
// or
ok := authenticator.VerifyTokenCustom(secret, code, 60)
```

Generate Url

```go
uri := authenticator.GenerateTotpUri("Foo", "bar", secret)
// or
url := authenticator.GenerateQRCodeGoogleUrl("Foo", "bar", secret)
```

## License

Apache License Version 2.0, http://www.apache.org/licenses/
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package googleauthenticator
package authenticator

import (
"crypto/rand"
Expand Down
34 changes: 34 additions & 0 deletions src/authenticator/authenticator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package authenticator_test

import (
"fmt"
"github.com/mix-go/authenticator"
"github.com/stretchr/testify/assert"
"testing"
)

func TestVerifyToken(t *testing.T) {
a := assert.New(t)

secret := authenticator.GenerateSecret()
code := authenticator.GenerateToken(secret)
ok := authenticator.VerifyToken(secret, code)
uri := authenticator.GenerateTotpUri("foo", "bar", secret)
url := authenticator.GenerateQRCodeGoogleUrl("foo", "bar", secret)
fmt.Printf("%v\n%s\n%s\n", ok, uri, url)

a.Equal(ok, true)
}

func TestPHPVerifyToken(t *testing.T) {
a := assert.New(t)

secret := "OQB6ZZGYHCPSX4AK"
code := authenticator.GenerateToken(secret)
ok := authenticator.VerifyToken(secret, code)
uri := authenticator.GenerateTotpUri("foo", "bar", secret)
url := authenticator.GenerateQRCodeGoogleUrl("foo", "bar", secret)
fmt.Printf("%v\n%s\n%s\n", ok, uri, url)

a.Equal(ok, true)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/mix-go/googleauthenticator
module github.com/mix-go/authenticator

go 1.20

Expand Down
File renamed without changes.
41 changes: 0 additions & 41 deletions src/googleauthenticator/README.md

This file was deleted.

34 changes: 0 additions & 34 deletions src/googleauthenticator/authenticator_test.go

This file was deleted.

0 comments on commit 81eabdc

Please sign in to comment.