add service
All checks were successful
Deploy Smart Search Backend / deploy (push) Successful in 1m47s

This commit is contained in:
vallyenfail
2026-01-20 19:02:06 +03:00
parent f8db0fd9e6
commit 8b9554720d
15 changed files with 2109 additions and 38 deletions

View File

@@ -6,11 +6,12 @@ import (
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
"crypto/sha512"
"encoding/hex"
"errors"
"fmt"
"strings"
"golang.org/x/crypto/bcrypt"
)
type Crypto struct {
@@ -31,10 +32,19 @@ func (c *Crypto) EmailHash(email string) string {
return hex.EncodeToString(h.Sum(nil))
}
const bcryptCost = 12
func PasswordHash(password string) string {
h := sha512.New()
h.Write([]byte(password))
return hex.EncodeToString(h.Sum(nil))
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcryptCost)
if err != nil {
return ""
}
return string(hash)
}
func PasswordVerify(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}
func (c *Crypto) getKey() []byte {