UserManager.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef USER_MANAGER_H
  2. #define USER_MANAGER_H
  3. #include <fstream>
  4. #include <iostream>
  5. #include <map>
  6. #include <sstream>
  7. #include <string>
  8. #include <vector>
  9. /**
  10. * @Class UserManager
  11. *
  12. * Handle differnt users with passwords and store them
  13. */
  14. class UserManager {
  15. public:
  16. /**
  17. * Makes shure that there is a user storage.
  18. * If not. It creates a new one
  19. */
  20. static void init(const std::string &file);
  21. /**
  22. * Checks if a given user with password is valid
  23. *
  24. * @param user the name of the users
  25. * @param pw password in plain text
  26. */
  27. static bool isAllowed(const std::string &user, const std::string &pw);
  28. /**
  29. * Add a new user and write to storage.
  30. *
  31. * @param user the name of the users
  32. * @param pw password in plain text
  33. */
  34. static void addUser(const std::string &name, const std::string &pw);
  35. /**
  36. * Delete a new user and delete from storage.
  37. *
  38. * @param user the name of the users
  39. * @param pw password in plain text
  40. */
  41. static void deleteUser(const std::string &name, const std::string &pw);
  42. private:
  43. /**
  44. * Name of the file which holds the user data
  45. */
  46. static std::string filename;
  47. /**
  48. * Read data from file and create map.
  49. *
  50. * @param user_map pointer to the map
  51. */
  52. static void readFromFile(std::map<std::string, std::string> &user_map);
  53. /**
  54. * Write data to afile
  55. *
  56. * @param user_map pointer to the map
  57. */
  58. static void writeToFile(std::map<std::string, std::string> &user_map);
  59. };
  60. #endif