This code simply receives a very basic 'password' (numbers, letters, nothing fancy). After you press enter, it will display it back. The only special key I'm handling is backspace (code
8 in ASCII).
uses crt; var pass: string; key: char; len: integer; begin clrscr; key := chr(0); pass := chr(0); write('Write the password:'); while key<>chr(13) do begin key := readkey; len := length(pass); case ord(key) of 8: begin if len > 0 then begin delete(pass, len, 1); end; end; else pass := concat(pass, key); end; end; writeln('Password: ', pass); readln; //pauses the code end.
You will probably notice that the
program block is missing. It was on purpose, since Free Pascal Compiler has issues with it.
The code compiles / runs fine, to the best of my knowledge. Remember that this is simply and purely made for ASCII 7-bit (I think the extended set will work).
In terms of clarity, structure and indentation, what else can I improve?