aboutsummaryrefslogtreecommitdiff
path: root/crypto/crypto.go
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/crypto.go')
-rw-r--r--crypto/crypto.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/crypto/crypto.go b/crypto/crypto.go
index 5e0b688f..684c2197 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -9,6 +9,8 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
+
+ "golang.org/x/crypto/bcrypt"
)
// HashFromBytes returns a SHA-256 checksum of the input.
@@ -41,3 +43,8 @@ func GenerateRandomString(size int) string {
func GenerateRandomStringHex(size int) string {
return hex.EncodeToString(GenerateRandomBytes(size))
}
+
+func HashPassword(password string) (string, error) {
+ bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
+ return string(bytes), err
+}