This commit is contained in:
ryan
2026-03-09 22:43:14 +08:00
commit 34f317fe6f
98 changed files with 20718 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
package common
import "golang.org/x/crypto/bcrypt"
func Password2Hash(password string) (string, error) {
passwordBytes := []byte(password)
hashedPassword, err := bcrypt.GenerateFromPassword(passwordBytes, bcrypt.DefaultCost)
return string(hashedPassword), err
}
func ValidatePasswordAndHash(password string, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}