ilk
This commit is contained in:
26
svc/internal/security/reset_token.go
Normal file
26
svc/internal/security/reset_token.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
func GenerateResetToken() (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 HashToken(plain string) string {
|
||||
sum := sha256.Sum256([]byte(plain))
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
Reference in New Issue
Block a user