Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.68 KB | None | 0 0
  1. Program Ej23_version3;
  2.  
  3. var
  4.     char1,char2:char;
  5.     mayus,minus,especial:boolean; // mayus and minus would be uppercase and lowercase respectively
  6.     cantDigitos,cantCaracteres,contrasenasValidas,cantidadDeContrasenas,cantidadDeContrasenasInvalidas:word;
  7.     datos,archivodeContrasenas:text;
  8.     palabra,palabraValida,invalidaMasLarga:string;
  9.     porcentajedeInvalidas:real;
  10.  
  11.  
  12. Begin
  13.     assign(datos,'Datos_guia3_ej23.txt'); reset(datos);
  14.     assign(archivodeContrasenas,'contraseñas_validas.txt'); rewrite(archivodeContrasenas);
  15.  
  16.     contrasenasValidas := 0; cantidadDeContrasenas := 0; cantidadDeContrasenasInvalidas := 0;
  17.    
  18.     char1 := ' ';
  19.  
  20.     invalidaMasLarga := '';
  21.  
  22.     Read(datos,char2);
  23.     while not eof(datos) do
  24.     Begin
  25.         mayus := false; minus := false; cantDigitos := 0; cantCaracteres := 0; especial := false;
  26.         palabra := '';
  27.         if (char1 = ' ') and (char2 <> ' ') then //check if its the beggining of the word
  28.         Begin
  29.             while not eof(datos) and (char2 <> ' ') do
  30.             Begin
  31.                 cantCaracteres := cantCaracteres + 1;
  32.                 if (char2 = '!') or (char2 = '"') or (char2 = '#') or (char2 = '$') or (char2 = '%') or (char2 = '&') or (char2 = '/') then
  33.                     especial := true;
  34.  
  35.  
  36.                 if (char2 in ['A'..'Z']) then  
  37.                     mayus := true
  38.                 else
  39.                     if (char2 in ['0'..'9']) then
  40.                     cantDigitos := cantDigitos + 1
  41.                     else
  42.                         minus := true;
  43.                 if eof(datos) then // when it reaches the end of the file, it also reads and checks the last character
  44.                     if (char2 in ['A'..'Z']) then
  45.                         mayus := true
  46.                     else
  47.                         if (char2 in ['0'..'9']) then
  48.                             cantDigitos := cantDigitos + 1
  49.                         else
  50.                             minus := true;
  51.            
  52.             palabra := palabra + char2;
  53.             Read(datos,char2);
  54.             End;
  55.            
  56.             cantidadDeContrasenas := cantidadDeContrasenas + 1;
  57.            
  58.             if minus and mayus and (cantDigitos = 4) and (cantCaracteres >= 8) and (not especial) then //if all conditions are met, the password is valid and its added to the counter
  59.                 Begin
  60.                 contrasenasValidas := contrasenasValidas + 1;
  61.                 palabraValida := palabra;
  62.                 WriteLn(archivodeContrasenas,palabraValida);
  63.                 End
  64.             else
  65.                 cantidadDeContrasenasInvalidas := cantidadDeContrasenasInvalidas + 1;
  66.                 if length(palabra) > length(invalidaMasLarga) then
  67.                     invalidaMasLarga := palabra;
  68.            
  69.  
  70.             char1 := char2; //char2 should be an empty character by this point, so it passes that value to char1 and reads the next character
  71.             while char2 = ' ' do
  72.                 Read(datos,char2)
  73.                
  74.  
  75.         End
  76.    
  77.     End;
  78.  
  79.     porcentajedeInvalidas := (cantidadDeContrasenasInvalidas*100)/cantidadDeContrasenas;
  80.     close(archivodeContrasenas);
  81.     WriteLn('Hay un ',porcentajedeInvalidas:2:2,'% de contraseñas inválidas');
  82. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement