Solved

Backspace in Password Field

Posted on 1998-02-13
9
884 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
Comment Utility
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
Comment Utility
how can i do that?
0
 
LVL 1

Expert Comment

by:FuzzyLogic
Comment Utility
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
 
LVL 2

Expert Comment

by:kellyjj
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:weinrj
Comment Utility
thank you...i will implement this into my code....
0
 

Author Comment

by:weinrj
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now