feat: add qr code alternative sign in method (#1594)

Co-authored-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
This commit is contained in:
Elias Schneider
2026-07-28 01:30:13 +02:00
committed by GitHub
parent 968f97fa61
commit e1fd1d320f
38 changed files with 2215 additions and 73 deletions

View File

@@ -19,10 +19,21 @@ func GenerateRandomAlphanumericString(length int) (string, error) {
// GenerateRandomUnambiguousString generates a random string of the given length using unambiguous characters
func GenerateRandomUnambiguousString(length int) (string, error) {
const charset = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789"
const charset = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ0123456789"
return GenerateRandomString(length, charset)
}
// GenerateRandomUppercaseUnambiguousString generates a random uppercase string of the given length using unambiguous characters
func GenerateRandomUppercaseUnambiguousString(length int) (string, error) {
const charset = "ABCDEFGHJKMNPQRSTUVWXYZ0123456789"
return GenerateRandomString(length, charset)
}
// NormalizeUnambiguousString converts commonly confused letters to the canonical digits used by generated codes
func NormalizeUnambiguousString(value string) string {
return strings.NewReplacer("I", "1", "i", "1", "O", "0", "o", "0").Replace(value)
}
// GenerateRandomString generates a random string of the given length using the provided character set
func GenerateRandomString(length int, charset string) (string, error) {
@@ -30,6 +41,10 @@ func GenerateRandomString(length int, charset string) (string, error) {
return "", errors.New("length must be a positive integer")
}
if len(charset) == 0 {
return "", errors.New("character set must not be empty")
}
// The algorithm below is adapted from https://stackoverflow.com/a/35615565
const (
letterIdxBits = 6 // 6 bits to represent a letter index