Documentation ¶
Overview ¶
Package passwd provides a secure way to manage passwords in Go without requiring any additional setup. The Password type is used just like a normal string, but provides additional functionality such as hashing and comparing passwords securely.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetHashComparer ¶
func SetHashComparer(hc HashComparer)
SetHashComparer sets the global hash comparer to the specified value. This function is concurrent-safe.
Types ¶
type HashComparer ¶
type HashComparer interface { // Hash generates a hash from the specified plaintext password using the configured algorithm. // It returns the resulting hash as a string and any errors that occur during the hash generation. Hash(plain string) (string, error) // Compare compares the specified plaintext password with the specified hash. // It returns an error if the comparison fails. Compare(hash string, plain string) error }
HashComparer is a contract for the hashing algorithm that can generate and compare hashes. To provide a custom implementation use the SetHashComparer function.
type Password ¶
type Password string
Password is a type that represents a password. It provides additional functionality for securely hashing and comparing passwords.
func (Password) Compare ¶
Compare compares the password with plain text. It returns an error if the comparison fails.
func (Password) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the password. It hides the actual password value by returning "FILTERED".
func (*Password) Scan ¶
Scan implements the sql.Scanner interface. It sets the password value to an empty string if the source value is nil. Otherwise, it sets the password value to the source value.