package crypto import ( "golang.org/x/crypto/bcrypt" ) // EncryptPassword 加密密碼 func EncryptPassword(pwd string) (string, error) { hash, err := bcrypt.GenerateFromPassword([]byte(pwd), bcrypt.DefaultCost) if err != nil { return "", err } return string(hash), nil } // CheckPassword 檢查密碼 func CheckPassword(pwd, hash string) error { return bcrypt.CompareHashAndPassword([]byte(hash), []byte(pwd)) }