Documentation ¶
Overview ¶
Package crypt implements a basic interface to validate crypt(3) hashes.
Validation of any particular hash requires the prior registration of a check function. Registration is typically automatic as a side effect of initializing that hash's package so that, to validate an Argon2 has, it suffices to have
import _ "github.com/sergeymakinen/go-crypt/argon2"
in a program's main package. The _ means to import a package purely for its initialization side effects.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrHash = errors.New("unknown hash") ErrPasswordMismatch = errors.New("hash and password mismatch") )
Functions ¶
func Check ¶
Check compares the given crypt(3) hash with a new hash derived from the password. Returns nil on success, or an error on failure.
Example ¶
package main import ( "fmt" "github.com/sergeymakinen/go-crypt" _ "github.com/sergeymakinen/go-crypt/argon2" _ "github.com/sergeymakinen/go-crypt/bcrypt" ) var hashes = []string{ "$argon2id$v=19$m=512,t=3,p=1$qXMlAYBABLl$/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho", // Argon2 "$2b$12$mBhJFLLDJCBCcmMN4DLyrOV.LLSl/mdwGfzwsqvIL0OQN5yXzRihO", // bcrypt "$unknown$foo", // Not registered } var passwords = []string{ "password", "test", } func main() { for _, hash := range hashes { for _, password := range passwords { fmt.Printf("%q with %q: %v\n", hash, password, crypt.Check(hash, password)) } } }
Output: "$argon2id$v=19$m=512,t=3,p=1$qXMlAYBABLl$/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho" with "password": <nil> "$argon2id$v=19$m=512,t=3,p=1$qXMlAYBABLl$/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho" with "test": hash and password mismatch "$2b$12$mBhJFLLDJCBCcmMN4DLyrOV.LLSl/mdwGfzwsqvIL0OQN5yXzRihO" with "password": <nil> "$2b$12$mBhJFLLDJCBCcmMN4DLyrOV.LLSl/mdwGfzwsqvIL0OQN5yXzRihO" with "test": hash and password mismatch "$unknown$foo" with "password": unknown hash "$unknown$foo" with "test": unknown hash
func RegisterHash ¶
RegisterHash registers a hash for use by Check. Prefix is a prefix that identifies the hash. Check is the function that compares the given hash with a new hash derived from the password.
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package argon2 implements the Argon2 hashing algorithm for crypt(3).
|
Package argon2 implements the Argon2 hashing algorithm for crypt(3). |
argon2crypto
Package argon2crypto provides low-level access to Argon2 cryptography functions.
|
Package argon2crypto provides low-level access to Argon2 cryptography functions. |
Package bcrypt implements the bcrypt hashing algorithm for crypt(3).
|
Package bcrypt implements the bcrypt hashing algorithm for crypt(3). |
Package des implements the DES hashing algorithm for crypt(3).
|
Package des implements the DES hashing algorithm for crypt(3). |
descrypt
Package descrypt provides low-level access to DES crypt functions.
|
Package descrypt provides low-level access to DES crypt functions. |
Package desext implements the DES Extended hashing algorithm for crypt(3).
|
Package desext implements the DES Extended hashing algorithm for crypt(3). |
Package hash implements encoding and decoding of crypt(3) hashes.
|
Package hash implements encoding and decoding of crypt(3) hashes. |
base64le
Package base64le implements the little-endian variant of base64 encoding as specified by RFC 4648.
|
Package base64le implements the little-endian variant of base64 encoding as specified by RFC 4648. |
parse
Package parse builds parse trees for crypt(3) hashes.
|
Package parse builds parse trees for crypt(3) hashes. |
internal
|
|
Package md5 implements the MD5 hashing algorithm for crypt(3).
|
Package md5 implements the MD5 hashing algorithm for crypt(3). |
md5crypt
Package md5crypt provides low-level access to MD5 crypt functions.
|
Package md5crypt provides low-level access to MD5 crypt functions. |
Package nthash implements the NT Hash hashing algorithm for crypt(3).
|
Package nthash implements the NT Hash hashing algorithm for crypt(3). |
Package sha1 implements the SHA-1 hashing algorithm for crypt(3).
|
Package sha1 implements the SHA-1 hashing algorithm for crypt(3). |
Package sha256 implements the SHA-256 hashing algorithm for crypt(3).
|
Package sha256 implements the SHA-256 hashing algorithm for crypt(3). |
sha2crypt
Package sha2crypt provides low-level access to SHA-2 family crypt functions.
|
Package sha2crypt provides low-level access to SHA-2 family crypt functions. |
Package sha512 implements the SHA-512 hashing algorithm for crypt(3).
|
Package sha512 implements the SHA-512 hashing algorithm for crypt(3). |
Package sunmd5 implements the Sun MD5 hashing algorithm for crypt(3).
|
Package sunmd5 implements the Sun MD5 hashing algorithm for crypt(3). |