18 lines
387 B
Go
18 lines
387 B
Go
package auth
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
const bcryptCost = 10
|
|
|
|
func HashPassword(plain string) (string, error) {
|
|
bytes, err := bcrypt.GenerateFromPassword([]byte(plain), bcryptCost)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(bytes), nil
|
|
}
|
|
|
|
func CheckPassword(plain, hashed string) bool {
|
|
return bcrypt.CompareHashAndPassword([]byte(hashed), []byte(plain)) == nil
|
|
}
|