From 20cb29c2f8c5c87bc590896854a20b1473ceb358 Mon Sep 17 00:00:00 2001 From: "info@mode42.com" Date: Sat, 8 Aug 2026 03:54:55 +0000 Subject: #2 --- include/hybbx/password.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 include/hybbx/password.h (limited to 'include/hybbx/password.h') diff --git a/include/hybbx/password.h b/include/hybbx/password.h new file mode 100644 index 0000000..cc1b38e --- /dev/null +++ b/include/hybbx/password.h @@ -0,0 +1,53 @@ +#ifndef HYBBX_PASSWORD_H +#define HYBBX_PASSWORD_H + +#include "hybbx/types.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Stored password prefix for SHA-256 (default, tinysha256). */ +#define HYBBX_PASSWORD_SHA256_PREFIX "{sha256}" +/** Stored password prefix for legacy MD5 (verify-only fallback). */ +#define HYBBX_PASSWORD_MD5_PREFIX "{md5}" + +/** Max stored password field: prefix + 64 hex digits + NUL. */ +#define HYBBX_PASSWORD_STORED_MAX 96 + +/** Non-zero when @p stored is a hashed password (sha256 or md5 prefix). */ +int hybbx_password_is_hashed(const char *stored); + +/** Non-zero when @p stored is plain text and should be upgraded on load. */ +int hybbx_password_is_plain(const char *stored); + +/** + * Hash @p plain into @p out as {sha256} using the configured backend + * (default: bundled tinysha256; see [crypto] password_hash in hybbx.ini). + */ +hybbx_result_t hybbx_password_hash_sha256(const char *plain, + char *out, + size_t out_size); + +/** Hash @p plain with the configured default algorithm (SHA-256). */ +hybbx_result_t hybbx_password_hash(const char *plain, char *out, size_t out_size); + +/** Return non-zero when @p provided matches @p stored (plain, sha256, or md5). */ +int hybbx_password_match(const char *stored, const char *provided); + +/** + * Fill @p out with a random password of length @p min_len … @p max_len using + * characters a-z and 0-9 only. + */ +hybbx_result_t hybbx_password_generate_alnum(char *out, + size_t out_size, + size_t min_len, + size_t max_len); + +#ifdef __cplusplus +} +#endif + +#endif /* HYBBX_PASSWORD_H */ -- cgit v1.3.1