Last active
April 17, 2023 00:08
-
-
Save cjaewon/dece2b4b7b4adc14a0d4b561276157c0 to your computer and use it in GitHub Desktop.
Revisions
-
cjaewon revised this gist
Jan 15, 2023 . No changes.There are no files selected for viewing
-
cjaewon revised this gist
Jan 15, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ func (cv *CustomValidator) Init() { password := fl.Field().String() if utf8.RuneCountInString(password) <= 30 && utf8.RuneCountInString(password) >= 6 { hasSuitableLen = true } -
cjaewon revised this gist
Jan 5, 2021 . 1 changed file with 1 addition and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,11 @@ package main import ( "v/utils" "os" "github.com/go-playground/validator/v10" ) func init() { -
cjaewon created this gist
Jan 5, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ package main import ( "mealbot/constants" "mealbot/ent" "mealbot/routes" "mealbot/utils" "os" "github.com/go-playground/validator/v10" _ "github.com/go-sql-driver/mysql" "github.com/gorilla/sessions" env "github.com/joho/godotenv" "github.com/labstack/echo-contrib/session" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" log "github.com/sirupsen/logrus" ) func init() { env.Load(".env") } func main() { e := echo.New() e.Validator = &utils.CustomValidator{Validator: validator.New()} e.Logger.Fatal(e.Start("1234")) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ package utils import ( "unicode" "unicode/utf8" "github.com/go-playground/validator/v10" ) // CustomValidator is type setting of third party validator type CustomValidator struct { Validator *validator.Validate } // Init validator func (cv *CustomValidator) Init() { cv.Validator.RegisterValidation("password", func(fl validator.FieldLevel) bool { var ( hasNumber = false hasSpecialChar = false hasLetter = false hasSuitableLen = false ) password := fl.Field().String() if utf8.RuneCountInString(password) <= 30 || utf8.RuneCountInString(password) >= 6 { hasSuitableLen = true } for _, c := range password { switch { case unicode.IsNumber(c): hasNumber = true case unicode.IsPunct(c) || unicode.IsSymbol(c): hasSpecialChar = true case unicode.IsLetter(c) || c == ' ': hasLetter = true default: return false } } return hasNumber && hasSpecialChar && hasLetter && hasSuitableLen }) } // Validate Data func (cv *CustomValidator) Validate(i interface{}) error { return cv.Validator.Struct(i) }