func Cost(hpwd []byte) (int, error) {
	bs := bytes.Split(hpwd, delim)
	cost, err := strconv.ParseUint(string(bs[costIndex]), base, bitSize)
	if err != nil {
		return -1, err
	}
	return int(cost), nil
}
Cost returns the work factor used to create the given hashed password.
When, in the future, the work factor needs to be increased in order to
adjust for greater computational power, this function allows one to
establish which passwords need to be updated.
package pwdhash
import (
	"bytes"
	"crypto/rand"
	"crypto/subtle"
	"encoding/base64"
	"strconv"
	"golang.org/x/crypto/pbkdf2"
)
func CompareHashAndPassword(hpwd, pwd []byte) error {
	alg, cost, salt, digest, err := validateHashFormat(hpwd)
	if err != nil {
		return err
	}
	n := len(digest)
	guess, err := GenerateFromPassword(pwd, salt, cost, n, alg)
	if err != nil {
		return err
	}
	res := subtle.ConstantTimeCompare(hpwd, guess)
	if res != 1 {
		return ErrMismatchedHashAndPassword
	}
	return nil
}