From 2c35b3abc877458325fcf598776e0cef0123e525 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Thu, 1 Apr 2021 20:38:46 -0700 Subject: [PATCH] :bulb: Comments --- include/user.hpp | 35 ++++++++++++++++++++++++++++++++++- main.cpp | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/user.hpp b/include/user.hpp index 090ed68..f299925 100644 --- a/include/user.hpp +++ b/include/user.hpp @@ -12,6 +12,19 @@ private: std::mutex pass_lock; public: + /** + * @brief User constructor + * + * @param init_pass initial password + */ + User(std::string &&init_pass) : password(init_pass) {} + + /** + * @brief User Constructor for admins + * + * @param init_bal initial balance + * @param init_pass initial password + */ User(uint_fast64_t init_bal, std::string &&init_pass) : balance(init_bal), password(init_pass) {} bool ChangePassword(const std::string &attempt, std::string &&new_pass) @@ -25,7 +38,16 @@ public: return state; } - friend bool SendFunds(User &a, User &b, uint_fast64_t amount, const std::string &attempt) + /** + * @brief SendFunds allows sending of money between users if verification is provided in the form of a password and if the user has sufficient funds + * + * @param a first user + * @param b second user + * @param amount amount being sent + * @param attempt password of first user + * @return wether transaction was succesful + */ + static bool SendFunds(User &a, User &b, uint_fast64_t amount, const std::string &attempt) { bool state; { @@ -43,12 +65,23 @@ public: return state; } + /** + * @brief Get the balance of the User object + * + * @return the balance + */ uint_fast64_t GetBal() { std::lock_guard lock{bal_lock}; return balance; } + /** + * @brief Used for Verification of password by external services, this can be used for logging in or signature + * + * @param attempt the password + * @return wether the passwords match + */ bool VerifyPassword(const std::string &attempt) //for connected services { std::lock_guard lock{pass_lock}; diff --git a/main.cpp b/main.cpp index ea8b186..5b5d1a7 100644 --- a/main.cpp +++ b/main.cpp @@ -6,7 +6,7 @@ int main() User a(1000, "pass123"); User b(0, "pass123"); a.ChangePassword("pass123", "newpass123"); - SendFunds(a, b, 250, "newpass123"); + User::SendFunds(a, b, 250, "newpass123"); a.GetBal(); a.VerifyPassword("newpass124");