package utils

import (
	"golang.org/x/crypto/bcrypt"
)

func Password(password string) (string, error) {
	// 密码加密
	hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		return "", err
	}
	//log.DebugF("原始密码:%v,加密后密码:%v", password, string(hashedPassword))
	return string(hashedPassword), nil
}

func CheckPassword(password, hashedPassword string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
	return err == nil // 返回 true 表示密码匹配
}
