summaryrefslogtreecommitdiff
path: root/src/user.h
diff options
context:
space:
mode:
authorNikita Kostovsky <nikita@kostovsky.me>2025-06-22 21:39:13 +0200
committerNikita Kostovsky <nikita@kostovsky.me>2025-06-22 21:39:13 +0200
commitc9fcceb74d861525b2defec8219374edb9c1455a (patch)
treefc10d7c2abcb08db76946e0bfd73f6b93a652422 /src/user.h
parentf674e179d602d3ccb9818d28fe06f371059449dc (diff)
add User class
Diffstat (limited to 'src/user.h')
-rw-r--r--src/user.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/user.h b/src/user.h
new file mode 100644
index 0000000..6826ed4
--- /dev/null
+++ b/src/user.h
@@ -0,0 +1,54 @@
+#pragma once
+
+#include <QString>
+
+// TODO: tests
+// - empty fields
+// - too long fields (use arrays instead of QByteArray?)
+// - try to break salt/hash fields
+
+// TODO: make all public fields private
+class User
+{
+public:
+ /*!
+ * \brief User - create user with given `login` and `password`. `salt` and
+ * `passwordHash` will be generated and stored instead of real `password`.
+ * Will *not* be committed to db automatically.
+ * \param login - max len is 32
+ * \param password - max len is 32
+ */
+ explicit User(const QString &login, const QString &password);
+
+public:
+ /*!
+ * \brief getDbId - check if user with corresponding `link` exists in db
+ * and return db id if any
+ * \return id on success, 0 otherwise
+ */
+ int getDbId();
+
+ /*!
+ * \brief createInDb - create user in db
+ * \return new user id on success, 0 otherwise
+ */
+ int createInDb();
+
+ /*!
+ * \brief getOrInsertDbId - get existing user id or try to create a new
+ * user and get its id
+ * \return existing or new user id on success, 0 otherwise
+ */
+ int getOrInsertDbId();
+
+ bool verifyPassword(const QString &password);
+
+public:
+ int id{0};
+ QString login;
+ QByteArray salt;
+ QByteArray passwordHash;
+
+private:
+ QByteArray hashPassword(const QString &password);
+};