💡 Comments

This commit is contained in:
EntireTwix 2021-04-01 20:38:46 -07:00
parent 33c3abf84b
commit 2c35b3abc8
2 changed files with 35 additions and 2 deletions

View file

@ -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<std::mutex> 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<std::mutex> lock{pass_lock};

View file

@ -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");