Advertisement
akevintg

Password Test (fork & pipe)

Nov 3rd, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.62 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. //link soal : https://www.dropbox.com/s/m6oztmzpuvy6m8e/O1-T0316-WM01-05.pdf?dl=0
  8.  
  9. int main(){
  10.     pid_t pFork;
  11.     int pi[2];
  12.     char pass[100];
  13.     int huruf,angka,ascii,i,pStrength;
  14.     if(pipe(pi)<0)
  15.         printf("Pipe ERROR");
  16.     pFork=fork();
  17.     if(pFork<0)
  18.         printf("Error");
  19.     else if(pFork==0){
  20.         printf("Child Process\n===========\n");
  21.         do{
  22.             printf("Masukan Password[5-20]: ");
  23.             scanf("%s",pass);getchar();
  24.         }while(strlen(pass)>20||strlen(pass)<5);
  25.         close(pi[0]);
  26.         write(pi[1],&pass,sizeof(pass));
  27.         sleep(1);
  28.     }
  29.     else if(pFork>0){
  30.         close(pi[1]);
  31.         read(pi[0],&pass,sizeof(pass));
  32.         printf("Parent Process\n===========\n");
  33.         printf("Your Password is \"%s \" \n",pass);
  34.         huruf=0;
  35.         angka=0;
  36.         ascii=0;
  37.         for(i=0;i<strlen(pass);i++){
  38.             if(isalpha(pass[i]))
  39.                 huruf++;
  40.             else if(isdigit(pass[i]))
  41.                 angka++;
  42.             else
  43.                 ascii++;
  44.         }
  45.         printf("Jumlah Huruf : %d\n",huruf);
  46.         printf("Jumlah Angka : %d\n",angka);
  47.         printf("Jumlah ASCII : %d\n",ascii);
  48.         printf("Panjang Pswd : %ld\n",strlen(pass));
  49.         pStrength=0;
  50.         if(strlen(pass)>=5&&strlen(pass)<=13)
  51.             pStrength++;
  52.         else if(strlen(pass)>13)
  53.             pStrength+=2;
  54.         if(huruf>=2&&huruf<=3)
  55.             pStrength++;
  56.         else if(huruf>3)
  57.             pStrength+=2;
  58.         if(angka>=2&&angka<=3)
  59.             pStrength++;
  60.         else if(angka>3)
  61.             pStrength+=2;
  62.         if(ascii>=2&&ascii<=3)
  63.             pStrength++;
  64.         else if(ascii>3)
  65.             pStrength+=2;
  66.         if(pStrength<4)
  67.             printf("Password Lemah\n");
  68.         else if(pStrength<=6)
  69.             printf("Password Normal\n");
  70.         else
  71.             printf("Password Kuat\n");
  72.  
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement