⚡ login performance optimization
This commit is contained in:
15
utils/get_ip.go
Normal file
15
utils/get_ip.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package utils
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
// GetClientIP 工具函数,获取客户端IP
|
||||
func GetClientIP(c *gin.Context) string {
|
||||
ip := c.GetHeader("X-Real-IP")
|
||||
if ip == "" {
|
||||
ip = c.GetHeader("X-Forwarded-For")
|
||||
}
|
||||
if ip == "" {
|
||||
ip = c.ClientIP()
|
||||
}
|
||||
return ip
|
||||
}
|
@@ -30,3 +30,10 @@ func IsUsername(username string) bool {
|
||||
match, _ := regexp.MatchString(phoneRegex, username)
|
||||
return match
|
||||
}
|
||||
|
||||
// IsPassword 密码的正则表达式
|
||||
func IsPassword(password string) bool {
|
||||
phoneRegex := `^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{6,18}$`
|
||||
match, _ := regexp.MatchString(phoneRegex, password)
|
||||
return match
|
||||
}
|
||||
|
Reference in New Issue
Block a user