mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-05 16:56:22 +00:00
⚡ implement email verification feature, add captcha validation middleware, and enhance user authentication flow
This commit is contained in:
27
pkg/utils/strings.go
Normal file
27
pkg/utils/strings.go
Normal file
@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
import "math/rand"
|
||||
|
||||
type stringsUtils struct{}
|
||||
|
||||
var Strings = stringsUtils{}
|
||||
|
||||
func (s *stringsUtils) GenerateRandomString(length int) string {
|
||||
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
result := make([]byte, length)
|
||||
for i := range result {
|
||||
result[i] = charset[rand.Intn(len(charset))]
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
func (s *stringsUtils) GenerateRandomStringWithCharset(length int, charset string) string {
|
||||
if charset == "" {
|
||||
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
}
|
||||
result := make([]byte, length)
|
||||
for i := range result {
|
||||
result[i] = charset[rand.Intn(len(charset))]
|
||||
}
|
||||
return string(result)
|
||||
}
|
Reference in New Issue
Block a user