XU XUv0.8.8
中文

API

#crypto/password

import: #crypto/password

counts: 4 fns, 0 methods, 0 types, 0 consts, 0 ifaces

Password hashing. Public PBKDF2-HMAC-SHA256 (the primitive that lived only inside the postgres SCRAM path) plus a self-describing encoded hash for login $pbkdf2-sha256$<iterations>$<salt_b64>$<dk_b64> Argon2id is the preferred long-term KDF; it needs a runtime ncall and is not in this package yet. Use a high iteration count until then. XU-CT-USE: fixed-shape-only verify compares digests with crypto/subtle.

pbkdf2_hmac_sha256

XuAPI
pub fn pbkdf2_hmac_sha256(password string, salt string, iterations int, key_len int) string

Purpose

pbkdf2_hmac_sha256 returns `key_len` raw bytes (RFC 2898). Throws on failure.

Parameters

password string
password (string)
salt string
salt (string)
iterations int
iterations (int)
key_len int
key_len (int)

Returns

string — result string

hash

XuAPI
pub fn hash(password string) string

Purpose

hash returns `$pbkdf2-sha256$iter$salt_b64$dk_b64`.

Parameters

password string
password (string)

Returns

string — result string

hash_iter

XuAPI
pub fn hash_iter(password string, iterations int) string

Purpose

Hash iter. Throws on failure.

Parameters

password string
password (string)
iterations int
iterations (int)

Returns

string — result string

verify

XuAPI
pub fn verify(encoded string, password string) bool

Purpose

verify reports whether password matches an encoded hash.

Parameters

encoded string
encoded (string)
password string
password (string)

Returns

bool — true or false