Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. int log()
  2. {
  3. FILE *file, *pipe;
  4. bool isWrong = true;
  5. char usern[25], pass[25], temp[25];
  6.  
  7. puts("Enter your username: ");
  8. scanf("%s", usern);
  9. puts("Enter your password: ");
  10. scanf("%s", pass);
  11.  
  12. /* Check if file is opened */
  13. file = fopen("record.txt", "r");
  14. if(!file)
  15. {
  16. printf("ERROR: FILE COULD NOT BE READ!an");
  17. exit(1);
  18. }
  19.  
  20. pipe = popen("open ssl pass", "r");
  21.  
  22.  
  23. /* Open the file, read until the end. If the user name is found, check the password entered */
  24. while(fgets(temp, 25, file)!= NULL && isWrong){
  25. if((strstr(temp, usern)) != NULL)
  26. {
  27. if((strstr(temp, pass))!=NULL)
  28. {
  29. isWrong = false;
  30. printf("Welcome %sn", usern);
  31. return 1;
  32. }
  33. else
  34. return 2;
  35. }
  36. }
  37.  
  38. fclose(file);
  39. }
  40.  
  41. /* The newUser function allows a user to register their name and password. */
  42. void newUser(){
  43.  
  44. FILE *file, *pipe;
  45. int i;
  46. char usern[25], pass[25];
  47.  
  48. puts("Enter a username: ");
  49. scanf("%s", usern);
  50. puts("Enter a password: ");
  51. scanf("%s", pass);
  52.  
  53. clear();
  54.  
  55. /* Don't be a noob and open the file to write, otherwise every time you register a new user, you'll overwrite the old info :| Open it to append! */
  56.  
  57. file = fopen("record.txt", "a");
  58. if(!file) /* Checks if the file is opened */
  59. {
  60. printf("ERROR FILE COULD NOT BE OPENEDan");
  61. exit(1);
  62. }
  63.  
  64. pipe = popen("openssl passwd", "w");
  65. if(pipe != NULL)
  66. {
  67. fwrite(pass, sizeof(char), strlen(pass), pipe);
  68. pclose(pipe);
  69. }
  70. /* Writes the file */
  71. fprintf(file, "%st%sn", usern, pass);
  72. pclose(pipe);
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement