Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Ej23_version3;
- var
- char1,char2:char;
- mayus,minus,especial:boolean; // mayus and minus would be uppercase and lowercase respectively
- cantDigitos,cantCaracteres,contrasenasValidas,cantidadDeContrasenas,cantidadDeContrasenasInvalidas:word;
- datos,archivodeContrasenas:text;
- palabra,palabraValida,invalidaMasLarga:string;
- porcentajedeInvalidas:real;
- Begin
- assign(datos,'Datos_guia3_ej23.txt'); reset(datos);
- assign(archivodeContrasenas,'contraseñas_validas.txt'); rewrite(archivodeContrasenas);
- contrasenasValidas := 0; cantidadDeContrasenas := 0; cantidadDeContrasenasInvalidas := 0;
- char1 := ' ';
- invalidaMasLarga := '';
- Read(datos,char2);
- while not eof(datos) do
- Begin
- mayus := false; minus := false; cantDigitos := 0; cantCaracteres := 0; especial := false;
- palabra := '';
- if (char1 = ' ') and (char2 <> ' ') then //check if its the beggining of the word
- Begin
- while not eof(datos) and (char2 <> ' ') do
- Begin
- cantCaracteres := cantCaracteres + 1;
- if (char2 = '!') or (char2 = '"') or (char2 = '#') or (char2 = '$') or (char2 = '%') or (char2 = '&') or (char2 = '/') then
- especial := true;
- if (char2 in ['A'..'Z']) then
- mayus := true
- else
- if (char2 in ['0'..'9']) then
- cantDigitos := cantDigitos + 1
- else
- minus := true;
- if eof(datos) then // when it reaches the end of the file, it also reads and checks the last character
- if (char2 in ['A'..'Z']) then
- mayus := true
- else
- if (char2 in ['0'..'9']) then
- cantDigitos := cantDigitos + 1
- else
- minus := true;
- palabra := palabra + char2;
- Read(datos,char2);
- End;
- cantidadDeContrasenas := cantidadDeContrasenas + 1;
- 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
- Begin
- contrasenasValidas := contrasenasValidas + 1;
- palabraValida := palabra;
- WriteLn(archivodeContrasenas,palabraValida);
- End
- else
- cantidadDeContrasenasInvalidas := cantidadDeContrasenasInvalidas + 1;
- if length(palabra) > length(invalidaMasLarga) then
- invalidaMasLarga := palabra;
- char1 := char2; //char2 should be an empty character by this point, so it passes that value to char1 and reads the next character
- while char2 = ' ' do
- Read(datos,char2)
- End
- End;
- porcentajedeInvalidas := (cantidadDeContrasenasInvalidas*100)/cantidadDeContrasenas;
- close(archivodeContrasenas);
- WriteLn('Hay un ',porcentajedeInvalidas:2:2,'% de contraseñas inválidas');
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement