user_manager.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef USER_MANAGER_H
  2. #define USER_MANAGER_H
  3. #include <map>
  4. #include <iostream>
  5. #include <fstream>
  6. #include <string>
  7. #include <vector>
  8. #include <sstream>
  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(std::string user, 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(std::string name, 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(std::string name, 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