📌  相关文章
📜  bcrypt golang - Go 编程语言 - Go 编程语言代码示例

📅  最后修改于: 2022-03-11 14:45:02.653000             🧑  作者: Mango

代码示例1
package util

import (
    "github.com/sirupsen/logrus"
    "golang.org/x/crypto/bcrypt"
)

func HashPassword(password string) string {
    pw := []byte(password)
    result, err := bcrypt.GenerateFromPassword(pw, bcrypt.DefaultCost)
    if err != nil {
        logrus.Fatal(err.Error())
    }
    return string(result)
}

func ComparePassword(hashPassword string, password string) error {
    pw := []byte(password)
    hw := []byte(hashPassword)
    err := bcrypt.CompareHashAndPassword(hw, pw)
    return err
}