Solved

Backspace in Password Field

Posted on 1998-02-13
9
893 Views
Last Modified: 2008-02-26
If i am using a password field in this kind of program, i want to know how to use backspace as a function not as #18/

the ascii charactor would get stored.  how do i make backspace actually backspace?  thanks...()
and if i had "*" echoing, how would i have the * erase?  i need both kind of password erasures....thanks

program getpassword;

uses
  crt;

var
  pass:string;
  c:char;

begin
  clrscr;
  textcolor(lightgray);
  write('Enter your password: ');
  pass:='';
  while c<>chr(13) do
  begin
    c:=readkey;
    if c<>#13 then
    begin
      pass:=pass+c;
    end;
  end;
  writeln;
  write('Status: ');
  textcolor(15);
  if pass = 'abc123' then writeln('Access Granted!')
  else writeln('Access Denied!');
  textcolor(7);
  write('Pass: ');
  textcolor(15);
  writeln(pass);
  textcolor(lightgreen);
  writeln; writeln('Program Terminated.');
  readkey
end.
0
Comment
Question by:weinrj
  • 5
  • 3
9 Comments
 
LVL 2

Accepted Solution

by:
kellyjj earned 20 total points
ID: 1217310
I would use a array of char. Then I would use the loop and readkey to read each individual char.  I would also use 'gotoxy(x,y)' for the location of each char.  This way when a backspace key is hit you can simply write out char (32) to minus 1 from x.
0
 

Author Comment

by:weinrj
ID: 1217311
how can i do that?
0
 
LVL 1

Expert Comment

by:FuzzyLogic
ID: 1217312
Simplier way is to write(#8,' ',#8) when BackSpace is pressed.
This way you don't need the gotoxy(). However, it works fine only if you don't have line-split.
just add an if statement:
  if (c=#8) begin;
    dec(byte(pass[0]));
    write(#8,' ',#8);
    continue;
  end;
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 2

Expert Comment

by:kellyjj
ID: 1217313
while (x<>char(13)) do
begin
  x=readkey();
  if (x<>char(8))
  begin
    pas_ary[y]=x;
    gotoxy(z,y); write("*");
    inc(z);
    inc(y);
  end
  else
  begin
     dec(z);
     gotoxy(z,y); write(" ");
  end;
end
0
 

Author Comment

by:weinrj
ID: 1217314
thank you...i will implement this into my code....
0
 

Author Comment

by:weinrj
ID: 1217315
uh, kelly, can u let me know how to use that code....my project
uses an entirely different way of doing things.  thanks....
0
 

Author Comment

by:weinrj
ID: 1217316
another note....if the cursor is not moving in my program example, how do i backspace the last stored information
0
 
LVL 2

Expert Comment

by:kellyjj
ID: 1217317
could you clearify what you mean by using a different meathod? Also, I would do a search for some assembler tutorials, interrupt listings.  There assembler rountines that control the cursor which are only a few lines.  Knowing assembler would be a great thing since you are using pascal.  I use assembler quite a bit with both pascal and C.
0
 

Author Comment

by:weinrj
ID: 1217318
If this question is directed to me, the only thing i can help you with is cursorOn and cursorOff procedures.  I dont know any asm other than that.  i do want to learn myself, and i hope to learn it soon....

Procedure hideCursor; assembler;

asm
 mov es,[Seg0040]
 mov di,0060h
 mov cx,word ptr es:[di]
 mov ax,0100h
 or  ch,20h
 int 10h
end;

Procedure showCursor; assembler;

asm
 mov es,[Seg0040]
 mov di,0060h
 mov cx,word ptr es:[di]
 mov ax,0100h
 and ch,0dfh
 int 10h
end;


there ya go.....
NOTE:  If you do know assembler, this looks different than the true asm statements.  I had a friend tell me what to do.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get TStatusBar text from another application - Delphi 7 4 1,949
MAPI Error1: User cancelled request ? 7 1,164
access tor through embbed delphi browser 4 392
TEdit.SetFocus trouble 3 172
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
The question appears often enough, how do I transfer my data from my old server to the new server while preserving file shares, share permissions, and NTFS permisions.  Here are my tips for handling such a transfer.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question