package bcrypt

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

func New(b []byte) ([]byte, error) {
	return bcrypt.GenerateFromPassword(b, bcrypt.DefaultCost)
}

func NewString(s string) (string, error) {
	b, err := New([]byte(s))
	if err != nil {
		return "", err
	}
	return string(b), nil
}

func Equal(hashed, plain []byte) bool {
	return bcrypt.CompareHashAndPassword(hashed, plain) == nil
}

func EqualString(hashed, plain string) bool {
	return Equal([]byte(hashed), []byte(plain))
}
