first commit

This commit is contained in:
2022-12-13 07:42:44 +08:00
commit 7ef2644e20
46 changed files with 7810 additions and 0 deletions

22
pkg/api/encrypt.go Normal file
View File

@@ -0,0 +1,22 @@
package api
import (
"log"
"golang.org/x/crypto/bcrypt"
)
func EncryptPassword(password string) string {
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.MinCost)
if err != nil {
log.Println("Warning: Failed to hash password, fallback to plaintext password")
return password
}
return string(hash)
}
func ComparePassword(hashedPassword string, plainTextPassword string) error {
err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(plainTextPassword))
return err
}