mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-28 06:37:57 +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>
65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
package utils
|
|
|
|
import "strings"
|
|
|
|
var mask = "*"
|
|
|
|
func MaskEmail(email string) string {
|
|
if len(email) == 0 {
|
|
return ""
|
|
}
|
|
|
|
tmp := strings.Split(email, "@")
|
|
|
|
name := tmp[0]
|
|
domain := tmp[1]
|
|
|
|
nameRunes := []rune(name)
|
|
nameRunesLen := len(nameRunes)
|
|
|
|
if nameRunesLen == 0 {
|
|
return strings.Repeat(mask, 6) + "@" + domain
|
|
}
|
|
|
|
var maskStart, padLength int
|
|
if nameRunesLen <= 6 {
|
|
maskStart = 1
|
|
padLength = 6 - nameRunesLen
|
|
} else {
|
|
maskStart = 3
|
|
|
|
}
|
|
|
|
maskedAddress := ""
|
|
maskedAddress += string(nameRunes[:maskStart])
|
|
maskedAddress += strings.Repeat(mask, len(nameRunes[maskStart:])+padLength)
|
|
maskedAddress += "@" + domain
|
|
|
|
return maskedAddress
|
|
}
|
|
|
|
func MaskUsername(username string) string {
|
|
usernameRunes := []rune(username)
|
|
usernameRunesLen := len(usernameRunes)
|
|
|
|
if usernameRunesLen == 0 {
|
|
return ""
|
|
}
|
|
|
|
if usernameRunesLen == 1 {
|
|
return mask
|
|
}
|
|
|
|
padLength := 0
|
|
if usernameRunesLen <= 3 {
|
|
padLength = 6 - usernameRunesLen
|
|
}
|
|
|
|
maskedUsername := ""
|
|
maskedUsername += string(usernameRunes[0])
|
|
maskedUsername += strings.Repeat(mask, usernameRunesLen-2+padLength)
|
|
maskedUsername += string(usernameRunes[usernameRunesLen-1])
|
|
|
|
return maskedUsername
|
|
}
|