summaryrefslogtreecommitdiff
path: root/include/hybbx/password.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/hybbx/password.h')
-rw-r--r--include/hybbx/password.h53
1 files changed, 53 insertions, 0 deletions
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 <stddef.h>
+
+#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}<hex> 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 */
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com