This commit is contained in:
2026-02-11 17:46:22 +03:00
commit eacfacb13b
266 changed files with 51337 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
package security
import (
"crypto/rand"
"crypto/sha256"
"encoding/hex"
)
func GenerateRefreshToken() (plain string, hash string, err error) {
b := make([]byte, 32) // 256 bit
if _, err = rand.Read(b); err != nil {
return
}
plain = hex.EncodeToString(b)
sum := sha256.Sum256([]byte(plain))
hash = hex.EncodeToString(sum[:])
return
}
func HashRefreshToken(plain string) string {
sum := sha256.Sum256([]byte(plain))
return hex.EncodeToString(sum[:])
}