initial commit

This commit is contained in:
m.zare
2026-04-10 18:25:21 +03:30
commit 77ca6c34a3
263 changed files with 34470 additions and 0 deletions

32
pkg/hash/service.go Normal file
View File

@@ -0,0 +1,32 @@
package hash
import (
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"golang.org/x/crypto/bcrypt"
)
var (
ErrHash = errors.New("wrong hash value")
)
func Hash(ctx context.Context, payload string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(payload), bcrypt.DefaultCost)
if err != nil {
return "", ErrHash
}
return string(bytes), nil
}
func CompareHash(ctx context.Context, hash string, payload string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(payload))
return err == nil
}
func SHA256(ctx context.Context, payload string) string {
hash := sha256.Sum256([]byte(payload))
return hex.EncodeToString(hash[:])
}