Release v0.20: регистрация, авторизация, личный кабинет

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
shop
2026-05-16 17:31:56 +03:00
parent 4ea2b429b3
commit b3e3a06858
23 changed files with 981 additions and 27 deletions
+27
View File
@@ -0,0 +1,27 @@
package auth
import (
"errors"
"unicode/utf8"
"golang.org/x/crypto/bcrypt"
)
const (
minPasswordLen = 8
bcryptCost = 12
)
var ErrInvalidCredentials = errors.New("неверный email или пароль")
func HashPassword(password string) (string, error) {
if utf8.RuneCountInString(password) < minPasswordLen {
return "", errors.New("пароль должен быть не короче 8 символов")
}
b, err := bcrypt.GenerateFromPassword([]byte(password), bcryptCost)
return string(b), err
}
func CheckPassword(hash, password string) bool {
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil
}