Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Backspace in Password Field

Posted on 1998-02-13
9
Medium Priority
?
923 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 80 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
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

926 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