mirror of
https://github.com/Awuqing/BackupX.git
synced 2026-05-12 19:40:46 +08:00
18 lines
431 B
Go
18 lines
431 B
Go
package security
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
const PasswordCost = 12
|
|
|
|
func HashPassword(password string) (string, error) {
|
|
hashed, err := bcrypt.GenerateFromPassword([]byte(password), PasswordCost)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(hashed), nil
|
|
}
|
|
|
|
func ComparePassword(hashedPassword, plainPassword string) error {
|
|
return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(plainPassword))
|
|
}
|