mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
💡 Comments
This commit is contained in:
parent
33c3abf84b
commit
2c35b3abc8
2 changed files with 35 additions and 2 deletions
|
|
@ -12,6 +12,19 @@ private:
|
||||||
std::mutex pass_lock;
|
std::mutex pass_lock;
|
||||||
|
|
||||||
public:
|
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) {}
|
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)
|
bool ChangePassword(const std::string &attempt, std::string &&new_pass)
|
||||||
|
|
@ -25,7 +38,16 @@ public:
|
||||||
return state;
|
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;
|
bool state;
|
||||||
{
|
{
|
||||||
|
|
@ -43,12 +65,23 @@ public:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the balance of the User object
|
||||||
|
*
|
||||||
|
* @return the balance
|
||||||
|
*/
|
||||||
uint_fast64_t GetBal()
|
uint_fast64_t GetBal()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock{bal_lock};
|
std::lock_guard<std::mutex> lock{bal_lock};
|
||||||
return balance;
|
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
|
bool VerifyPassword(const std::string &attempt) //for connected services
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock{pass_lock};
|
std::lock_guard<std::mutex> lock{pass_lock};
|
||||||
|
|
|
||||||
2
main.cpp
2
main.cpp
|
|
@ -6,7 +6,7 @@ int main()
|
||||||
User a(1000, "pass123");
|
User a(1000, "pass123");
|
||||||
User b(0, "pass123");
|
User b(0, "pass123");
|
||||||
a.ChangePassword("pass123", "newpass123");
|
a.ChangePassword("pass123", "newpass123");
|
||||||
SendFunds(a, b, 250, "newpass123");
|
User::SendFunds(a, b, 250, "newpass123");
|
||||||
a.GetBal();
|
a.GetBal();
|
||||||
a.VerifyPassword("newpass124");
|
a.VerifyPassword("newpass124");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue