Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现bcrypt 加密password #2

Open
yaogengzhu opened this issue Oct 12, 2023 · 0 comments
Open

实现bcrypt 加密password #2

yaogengzhu opened this issue Oct 12, 2023 · 0 comments

Comments

@yaogengzhu
Copy link
Member

这里就放在工具函数中了,取名 md5.go

package utils

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

func EnCodeMD5(password string) string {

	// 生成 bcrypt 密码哈希
	hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		panic(err)
	}
	return string(hashedPassword)
}

func UnCodeMD5(password string, hashedPassword string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
	return err == nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant