UserManager.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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();
  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. * Read data from file and create map.
  45. *
  46. * @param user_map pointer to the map
  47. */
  48. static void readFromFile(std::map<std::string, std::string> &user_map);
  49. /**
  50. * Write data to afile
  51. *
  52. * @param user_map pointer to the map
  53. */
  54. static void writeToFile(std::map<std::string, std::string> &user_map);
  55. };
  56. #endif