mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-29 23:59:46 +08:00
This pull request introduces the new Flowpilot system along with several new features and various improvements. The key enhancements include configurable authorization, registration, and profile flows, as well as the ability to enable and disable user identifiers (e.g., email addresses and usernames) and login methods. --------- Co-authored-by: Frederic Jahn <frederic.jahn@hanko.io> Co-authored-by: Lennart Fleischmann <lennart.fleischmann@hanko.io> Co-authored-by: lfleischmann <67686424+lfleischmann@users.noreply.github.com> Co-authored-by: merlindru <hello@merlindru.com>
37 lines
745 B
Go
37 lines
745 B
Go
package flowpilot
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"io"
|
|
"math/big"
|
|
)
|
|
|
|
const letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
|
|
func init() {
|
|
assertAvailablePRNG()
|
|
}
|
|
|
|
func assertAvailablePRNG() {
|
|
// Assert that a cryptographically secure PRNG is available.
|
|
// Panic otherwise.
|
|
buf := make([]byte, 1)
|
|
_, err := io.ReadFull(rand.Reader, buf)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("crypto/rand is unavailable: Read() failed with %#v", err))
|
|
}
|
|
}
|
|
|
|
func generateRandomString(n int) (string, error) {
|
|
ret := make([]byte, n)
|
|
for i := 0; i < n; i++ {
|
|
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
ret[i] = letters[num.Int64()]
|
|
}
|
|
return string(ret), nil
|
|
}
|