OK i have a project the is due soon and i am stuck.. i need to make a program the you enter you pin and it displase it as ****.. can some one help me. Email ..

Dani AI

Generated

Good direction from and a solid nudge from toward using ReadKey. Two practical additions make masked PIN input behave like users expect: stop on Enter, allow Backspace to correct, enforce a maximum length, accept only digits, and never print or persist the PIN in cleartext. The short loop below shows the usual console pattern (needs the CRT unit):

{ masked PIN input loop — console (requires "uses crt") }
var
  pinBuf: string;
  ch: char;
  maxLen: Integer;
begin
  pinBuf := '';
  maxLen := 6;

  write('Enter PIN: ');
  while True do
  begin
    ch := ReadKey;
    if ch = #13 then { Enter }
      Break
    else if ch = #8 then { Backspace }
    begin
      if Length(pinBuf) > 0 then
      begin
        Delete(pinBuf, Length(pinBuf), 1);
        write(#8 + ' ' + #8); { erase last asterisk }
      end;
    end
    else if (ch >= '0') and (ch <= '9') and (Length(pinBuf) < maxLen) then
    begin
      pinBuf := pinBuf + ch;
      write('*');
    end;
  end;
  writeln; { move to next line }
  { pinBuf holds the entered digits — do not display or store it in plain text }
end;

For storing names, a tiny CSV or a simple flat-file is fine for homework. If using Delphi/Free Pascal, TStringList.SaveToFile is an easy route; otherwise a delimited file works as long as fields are sanitized (escape or quote commas, trim whitespace). Never store PINs alongside names in plaintext; for any sensitive credential use proper hashing/encryption and restrict file access.

Quick troubleshooting notes: include CRT for ReadKey, test Backspace behavior in the target console, and keep the PIN only in memory (clear buffers when done) — printing the PIN back (as in a demo) is okay for learning, but not for real use.

Recommended Answers

All 6 Replies

ok i think the program should look like this..

program pin;
uses crt;
var;
pin : real;
begin
writeln ('enter pin here');
read (pin);
for pin:= 1 to 9 do write ('*');
writeln (' Your pin is',pin);
end.

when i try to wok it doesn;t do what i want it to do,
also can some one tell me if you can save the information like
write ('enter you name');
readln (name);
save the name and then the last name in some sort of data base..

ok i think the program should look like this..

program pin;
uses crt;
var;
pin : real;
begin
writeln ('enter pin here');
read (pin);
for pin:= 1 to 9 do write ('*');
writeln (' Your pin is',pin);
end.

when i try to wok it doesn;t do what i want it to do,
also can some one tell me if you can save the information like
write ('enter you name');
readln (name);
save the name and then the last name in some sort of data base..

Take a look at the ReadKey function.

program pin;
uses
   crt;
var
   PinNumber: string;
   Done: Boolean;
   ACharacter: Char;
begin
   { Initialize variables. }
   Done := False;
   PinNumber := '';

   { Prompt user for input. }
   writeln;
   write('Enter your pin number: ');

   { Read input. }
   repeat
      ACharacter := ReadKey;
      case ACharacter of
         '0'..'9':
            begin
               write('*');
               PinNumber := PinNumber + ACharacter;
            end;
      else
         Done := True;
      end;
   until Done;

   { Display pin number. }
   writeln;
   writeln('Your pin number is: ' + PinNumber);
end.

Second part of your question:

Answer := YES; :lol:

program names;
uses
   SysUtils;
const
   DataFileName = 'C:\NAMES.TXT';
var
   DataFile: TextFile;
   FirstName: string;
   LastName: string;
begin
   { Prompt user for first name. }
   write('Enter your FIRST name: ');
   readln(FirstName);

   { Prompt user for last name. }
   write('Enter your LAST name: ');
   readln(LastName);

   { Open the file. }
   AssignFile(DataFile, DataFileName);
   if FileExists(DataFileName) then
   begin
      Append(DataFile);
   end
   else
   begin
      Rewrite(DataFile);
   end;

   { Write data to the file in comma delimited format. }
   writeln(DataFile, LastName + ',' + FirstName);

   { Make sure the file is written to disk, then close it. }
   Flush(DataFile);
   CloseFile(DataFile);
end.

Thank you very much..

JackRabbit, what did that have to do with his program???

C++

The OP asked if he could save the first and last names to some sort of a database. A text file can be considered a flat-file database so I gave him a simple example of saving to a text file.

It wouldn't be much more work to save to XML (another simple text file format). Of course he/she could establish a connection to a database management program like MySQL, PostgreSQL, MS Access, etc. and read/write to it but that's not quite as simple...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.