Spaces:
Configuration error
Configuration error
File size: 831 Bytes
b0f0dc1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 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
}
|