changes...

This commit is contained in:
KamilM1205 2025-09-22 22:12:49 +04:00
parent 41944884b4
commit ab4b53fd40
26 changed files with 600 additions and 51 deletions

View file

@ -0,0 +1,21 @@
package utils
import (
"fmt"
"golang.org/x/crypto/bcrypt"
)
func EncryptPassword(pass string) (string, error) {
var salted string
salt := "58_team:%s:1205secret"
salted = fmt.Sprintf(salt, pass)
hashed, err := bcrypt.GenerateFromPassword([]byte(salted), 12)
if err != nil {
return "", err
}
return string(hashed), nil
}

View file

@ -0,0 +1,25 @@
package utils
import (
"unicode"
"github.com/go-playground/validator/v10"
)
func PasswordValidator(fl validator.FieldLevel) bool {
password := fl.Field().Interface().(string)
var hasUpper, hasNumber, hasLower = false, false, false
for _, c := range password {
if unicode.IsUpper(c) {
hasUpper = true
} else if unicode.IsLower(c) {
hasLower = true
} else if unicode.IsDigit(c) {
hasNumber = true
}
}
return hasUpper && hasNumber && hasLower
}