lifedebugger's picture
Deploy files from GitHub repository
b0f0dc1
package validation
import (
v10 "github.com/go-playground/validator/v10"
"regexp"
)
func PasswordRule(fl v10.FieldLevel) bool {
password := fl.Field().String()
// Minimum 8 karakter
if len(password) < 8 {
return false
}
// Harus mengandung minimal satu huruf kecil
lowercase, _ := regexp.MatchString(`[a-z]`, password)
if !lowercase {
return false
}
// Harus mengandung minimal satu huruf besar
uppercase, _ := regexp.MatchString(`[A-Z]`, password)
if !uppercase {
return false
}
// Harus mengandung minimal satu angka
number, _ := regexp.MatchString(`[0-9]`, password)
if !number {
return false
}
// Harus mengandung minimal satu karakter spesial
specialChar, _ := regexp.MatchString(`[!@#\$%\^&\*\(\)_\+\-=\[\]{};':"\\|,.<>\/?~]`, password)
if !specialChar {
return false
}
return true
}