Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColumbiysky <c.7843543@gmail.com>2025-05-03 12:27:53 +0300
committerGitHub <noreply@github.com>2025-05-03 12:27:53 +0300
commit85cbad3ef420ffdd7fec8657d247fdfe5e03903d (patch)
tree56036fc74abb46dd5de231bd8eeeeea50e6fcf0c /util/crypto
parent3d54e330514293e9385258da773be1a0e927a7f5 (diff)
feat: hashing user passwords
solves problems #2944, #2783
Diffstat (limited to 'util/crypto')
-rw-r--r--util/crypto/crypto.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/util/crypto/crypto.go b/util/crypto/crypto.go
new file mode 100644
index 00000000..f600e7a6
--- /dev/null
+++ b/util/crypto/crypto.go
@@ -0,0 +1,15 @@
+package crypto
+
+import (
+ "golang.org/x/crypto/bcrypt"
+)
+
+func HashPasswordAsBcrypt(password string) (string, error) {
+ hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
+ return string(hash), err
+}
+
+func CheckPasswordHash(hash, password string) bool {
+ err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
+ return err == nil
+}