changes...
This commit is contained in:
parent
41944884b4
commit
ab4b53fd40
26 changed files with 600 additions and 51 deletions
21
internal/utils/password_crypt.go
Normal file
21
internal/utils/password_crypt.go
Normal 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
|
||||
}
|
||||
25
internal/utils/password_validator.go
Normal file
25
internal/utils/password_validator.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue