feat: implement sign in with SSO (#1119)

* feat: implement sign in with SSO

* chore: update

* chore: update

* chore: update
This commit is contained in:
boojack
2023-02-19 09:50:30 +08:00
committed by GitHub
parent 708049bb89
commit d0b8b076cf
14 changed files with 448 additions and 82 deletions

View File

@@ -1,6 +1,8 @@
package common
import (
"crypto/rand"
"math/big"
"net/mail"
"strings"
@@ -35,3 +37,24 @@ func Min(x, y int) int {
}
return y
}
var letters = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
// RandomString returns a random string with length n.
func RandomString(n int) (string, error) {
var sb strings.Builder
sb.Grow(n)
for i := 0; i < n; i++ {
// The reason for using crypto/rand instead of math/rand is that
// the former relies on hardware to generate random numbers and
// thus has a stronger source of random numbers.
randNum, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
if err != nil {
return "", err
}
if _, err := sb.WriteRune(letters[randNum.Uint64()]); err != nil {
return "", err
}
}
return sb.String(), nil
}