main_cli.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdio.h>
  2. #include "src/password_generator.h"
  3. int main(int argc, char * argv[])
  4. {
  5. if ( argc == 2 )
  6. {
  7. char * file_address = argv[1];
  8. FILE * accounts_csv = fopen(file_address, "r");
  9. if (accounts_csv == NULL)
  10. {
  11. printf("Failed to open: %s\n", file_address);
  12. return 1;
  13. }
  14. // Get keyword for input
  15. const char keyword[4096];
  16. printf("Enter keyword: ");
  17. scanf("%s", keyword);
  18. char line_buffer[1024], service_buffer[1024], username_buffer[1024];
  19. int length, special;
  20. while ( fgets(line_buffer, 1024, accounts_csv) )
  21. {
  22. if ( sscanf(line_buffer, "%[^,],%[^,],%d,%d", service_buffer, username_buffer, &length, &special) != 4)
  23. {
  24. continue;
  25. }
  26. char password[length + 1];
  27. generate_password(password, keyword, service_buffer, username_buffer, length, special);
  28. printf("/--------------------------------%s\n%s\n%s\n\n",
  29. service_buffer,
  30. username_buffer,
  31. password);
  32. }
  33. fclose(accounts_csv);
  34. }
  35. else if (argc == 5)
  36. {
  37. const char * service_buffer = argv[1];
  38. const char * username_buffer = argv[2];
  39. int length, special;
  40. sscanf(argv[3], "%d", &length);
  41. sscanf(argv[4], "%d", &special);
  42. // Get keyword for input
  43. char keyword[4096];
  44. printf("Enter keyword: ");
  45. scanf("%s", keyword);
  46. char password[length + 1];
  47. generate_password(password, keyword, service_buffer, username_buffer, length, special);
  48. printf("/--------------------------------%s\n%s\n%s\n\n",
  49. service_buffer,
  50. username_buffer,
  51. password);
  52. }
  53. }