Advertisement
Guest User

Untitled

a guest
Oct 29th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <string>
  4. using namespace std;
  5.  
  6. bool checkChars(char arg[])
  7. {
  8. for(unsigned int i = 0; i < strlen(arg); i++)
  9. if(!strchr("1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM", arg[i]))
  10. return false;
  11. return true;
  12. }
  13.  
  14. bool isOk(char arg[], int mode)
  15. {
  16. switch(mode)
  17. {
  18. case 0:
  19. if(checkChars(arg) == false)
  20. return false;
  21. break;
  22.  
  23. case 1:
  24. if(strlen(arg) < 3)
  25. {
  26. cout<<"Password is to short!";
  27. return false;
  28. }
  29. else
  30. {
  31. char aux[250];
  32. strcpy(aux, arg);
  33. for(int unsigned i = 0; i < strlen(aux); i++)
  34. aux[i] = tolower(aux[i]);
  35. if(strcmp(aux, arg) == 0)
  36. {
  37. cout<<"Password is insecure!";
  38. return false;
  39. }
  40. }
  41. break;
  42.  
  43. case 2:
  44. bool isAt = false, isDot = false;
  45. char leftAux[250], rightAux[250], aux[250];
  46.  
  47. for (int unsigned i = 0; i < strlen(arg); i++)
  48. if(arg[i] == '@')
  49. isAt = true;
  50. else
  51. {
  52. leftAux[i] = arg[i];
  53. leftAux[i+1] = '\0';
  54. }
  55. if(isAt == false || strlen(leftAux) < 1 || checkChars(leftAux) == false)
  56. return false;
  57.  
  58. strcpy(rightAux, strstr(arg, "@"));
  59. strcpy(rightAux, rightAux + 1);
  60.  
  61.  
  62. strcpy(aux, rightAux);
  63. leftAux[0] = rightAux[0] = '\0';
  64. for(int unsigned i = 0; i < strlen(aux); i++)
  65. if(aux[i] == '.')
  66. isDot = true ;
  67. else
  68. {
  69. leftAux[i] = aux[i];
  70. leftAux[i+1] = '\0';
  71. }
  72. if(isDot == false || strlen(leftAux) < 1 || checkChars(leftAux) == false)
  73. return false;
  74.  
  75. strcpy(rightAux, strstr(aux, "."));
  76. strcpy(rightAux, rightAux + 1);
  77. if(strlen(rightAux) < 2 || checkChars(rightAux) == false)
  78. return false;
  79.  
  80. break;
  81. }
  82. return true;
  83. }
  84.  
  85. int main(int argc, char *argv[])
  86. {
  87. bool u = false, p = false, e = false;
  88. string user, password, email;
  89.  
  90. for(int i = 1; i < argc; i = i + 2 )
  91. {
  92. if (u == false && !strcmp(argv[i], "-u"))
  93. {
  94. if(isOk(argv[i+1], 0) == false)
  95. {
  96. cout<<"Username is not valid!";
  97. return 1;
  98. }
  99. user = argv[i+1];
  100. u = true;
  101. }
  102. else if(p == false && !strcmp(argv[i], "-p"))
  103. {
  104. if(isOk(argv[i+1], 1) == false)
  105. return 1;
  106. password = argv[i+1];
  107. p = true;
  108. }
  109. else if(e == false && !strcmp(argv[i], "-e"))
  110. {
  111. if(isOk(argv[i+1], 2) == false)
  112. {
  113. cout<<"E-mail is not valid!";
  114. return 1;
  115. }
  116. email = argv[i+1];
  117. e = true;
  118. }
  119. }
  120.  
  121. if(e == true && p == true)
  122. cout<<"User "<<user<<" has the email "<<email<<" and the password "<<password;
  123. else if(e == true && p == false)
  124. cout<<"User "<<user<<" has the email "<<email;
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement