Files
bssapp/svc/internal/security/password_policy.go
2026-02-11 17:46:22 +03:00

36 lines
779 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package security
import (
"errors"
"regexp"
"strings"
)
var (
reUpper = regexp.MustCompile(`[A-Z]`)
reLower = regexp.MustCompile(`[a-z]`)
reDigit = regexp.MustCompile(`[0-9]`)
reSpecial = regexp.MustCompile(`[^A-Za-z0-9]`)
)
func ValidatePassword(pw string) error {
pw = strings.TrimSpace(pw)
if len(pw) < 8 {
return errors.New("Parola en az 8 karakter olmalı")
}
if !reUpper.MatchString(pw) {
return errors.New("Parola en az 1 büyük harf içermeli")
}
if !reLower.MatchString(pw) {
return errors.New("Parola en az 1 küçük harf içermeli")
}
if !reDigit.MatchString(pw) {
return errors.New("Parola en az 1 rakam içermeli")
}
if !reSpecial.MatchString(pw) {
return errors.New("Parola en az 1 özel karakter içermeli")
}
return nil
}