aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-25 07:01:46 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-25 07:01:46 +0100
commit895b5091904bee1eed34377aa52d1a8abfbe2fa8 (patch)
tree2887ab8b58c7821f452dbfe5e13086c1b45cf93a
parent68d06f6b826a9831f300a1c7c072076e0745d598 (diff)
fics_getsalt() -- initial revision
-rw-r--r--FICS/fics_getsalt.cpp46
-rw-r--r--FICS/fics_getsalt.h17
2 files changed, 63 insertions, 0 deletions
diff --git a/FICS/fics_getsalt.cpp b/FICS/fics_getsalt.cpp
new file mode 100644
index 0000000..95705b0
--- /dev/null
+++ b/FICS/fics_getsalt.cpp
@@ -0,0 +1,46 @@
+/*
+ * Written by Markus Uhlin <maxxe@rpblc.net>,
+ * 25 Dec 2023.
+ */
+
+#include <cstdio>
+#include <cstring>
+#include <random>
+
+#include "fics_getsalt.h"
+
+char *
+fics_getsalt(void)
+{
+ static bool init_done = false;
+ static const char legal_index[] =
+ "./0123456789"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz";
+ static char salt[FICS_SALT_SIZE];
+
+ if (!init_done) {
+ strcpy(salt, FICS_SALT_BEG);
+ init_done = true;
+ }
+
+ std::random_device rd;
+ std::mt19937 gen(rd());
+ std::uniform_int_distribution<size_t> dist(0, strlen(legal_index) - 1);
+
+ for (size_t i = 7; i < sizeof salt; i++)
+ salt[i] = legal_index[dist(gen)];
+ salt[sizeof salt - 1] = '\0';
+ return (&salt[0]);
+}
+
+#if SELF_TEST
+int
+main(void)
+{
+ puts(fics_getsalt());
+ puts(fics_getsalt());
+ puts(fics_getsalt());
+ return 0;
+}
+#endif
diff --git a/FICS/fics_getsalt.h b/FICS/fics_getsalt.h
new file mode 100644
index 0000000..c22f9c8
--- /dev/null
+++ b/FICS/fics_getsalt.h
@@ -0,0 +1,17 @@
+#ifndef FICS_GETSALT_H
+#define FICS_GETSALT_H
+
+#define FICS_SALT_BEG "$2b$10$"
+#define FICS_SALT_SIZE 30
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char *fics_getsalt(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif