Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
passwords Posted by killhha on 3 Dec 2008 at 12:03 PM
what i want to try and do is cover up the password with *. for instance when you are entering in the password insteaded of seeing 'program' you would see '*******'. is it possible to do it with only using crt? i havent learnt anything else yet. im a noob at pascal.

this is my program:

program password_program;
uses crt;
var
password:string;

label pass;
label correct;
label wrong;
label quit;

begin
pass:
clrscr;
writeln('please enter correct password:');
readln(password);

if password='program' then goto correct else goto wrong;

correct:
writeln('correct password! you may continue.');
readln;
goto quit;

wrong:
writeln('bad password! try again!');
readln;
goto pass;

quit:
end.
Report
Re: passwords Posted by Actor on 3 Dec 2008 at 4:06 PM
: what i want to try and do is cover up the password with *. for
: instance when you are entering in the password insteaded of seeing
: 'program' you would see '*******'. is it possible to do it with only
: using crt? i havent learnt anything else yet. im a noob at pascal.
:
: this is my program:
:
:
: 
: program password_program;
: uses crt;
: var
:    password:string;
:    ch : char ;  
: 
: label pass;
: label correct;
: label wrong;
: label quit;
: 
: begin
: pass:
: clrscr;
: writeln('please enter correct password:');

  password := '' ;                 { nul string }
  {
       readkey does not echo
  }
  ch := readkey ;                  { get first character ]
  while ord(ch) <> 13 do begin     { "ENTER" key exits loop }
     password := password + ch ;
     write ('*') ;                 { fake echo }
     ch := readkey                 { get next character }
  end ;
  writeln ;                        { fake an echo of the "ENTER" key } 

: 
: if password='program' then goto correct else goto wrong;
: 
: correct:
: writeln('correct password! you may continue.');
: readln;
: goto quit;
: 
: wrong:
: writeln('bad password! try again!');
: readln;
: goto pass;
: 
: quit:
: end.
: 
:

Report
Re: passwords Posted by Atex on 3 Dec 2008 at 11:52 PM
: : what i want to try and do is cover up the password with *. for
: : instance when you are entering in the password insteaded of seeing
: : 'program' you would see '*******'. is it possible to do it with only
: : using crt? i havent learnt anything else yet. im a noob at pascal.
: :
: : this is my program:
: :
: :
: : 
: : program password_program;
: : uses crt;
: : var
: :    password:string;
: :    ch : char ;  
: : 
: : label pass;
: : label correct;
: : label wrong;
: : label quit;
: : 
: : begin
: : pass:
: : clrscr;
: : writeln('please enter correct password:');
: 
:   password := '' ;                 { nul string }
:   {
:        readkey does not echo
:   }
:   ch := readkey ;                  { get first character ]
:   while ord(ch) <> 13 do begin     { "ENTER" key exits loop }
:      password := password + ch ;
:      write ('*') ;                 { fake echo }
:      ch := readkey                 { get next character }
:   end ;
:   writeln ;                        { fake an echo of the "ENTER" key } 
: 
: : 
: : if password='program' then goto correct else goto wrong;
: : 
: : correct:
: : writeln('correct password! you may continue.');
: : readln;
: : goto quit;
: : 
: : wrong:
: : writeln('bad password! try again!');
: : readln;
: : goto pass;
: : 
: : quit:
: : end.
: : 
: :
:
:

This supports Backspace is case you mistyped :)


uses crt;

var pwd:string;


function get_pwd(mask:char):string; {mask can be any printable character}
 var ch:char;
     s:string;
 begin
  write('Enter password: ');
  s:='';                                    {password set ot nil}
  repeat
   ch:=readkey;                             {read a key}
   case ord(ch) of
    8:{BckSp} if length(s)>0 then begin
               gotoxy(pred(wherex),wherey); {move cursor to left}
               write(#32);                  {print space to erase last char.}
               gotoxy(pred(wherex),wherey); {move cursor to left}
               if length(s)=1 then s:='' else s:=copy(s,1,pred(length(s)));
               {if password length is 1 then set password to nil}
              end else write(#7); {Beeps if 0 length}
    32..127:{Spc..~}if length(s)<255 then begin
                s:=s+ch;
                write(mask);
               end else write(#7);

   end;
  until ord(ch)=13; {Enter}
  writeln;          {CR+LF}
  get_pwd:=s;
 end;


begin
 pwd:=get_pwd('*');
 writeln('Password is: ',pwd);
end.

Report
Re: passwords Posted by killhha on 3 Dec 2008 at 11:53 PM
thanks! it works. is it possible to make the letters horrizontal?

Report
Re: passwords Posted by Atex on 4 Dec 2008 at 12:35 AM
: thanks! it works. is it possible to make the letters horrizontal?
:
:
Not with simple pascal commands. But it is possible to remap the whole VGA character set, even to have 512 characters on hand. If you good with assembly, I think I have some code somewhere... On the other hand it's easily done in graphics mode ( settextstyle ).
Report
Re: passwords Posted by killhha on 4 Dec 2008 at 1:53 AM
: : thanks! it works. is it possible to make the letters horrizontal?
: :
: :
: Not with simple pascal commands. But it is possible to remap the
: whole VGA character set, even to have 512 characters on hand. If you
: good with assembly, I think I have some code somewhere... On the
: other hand it's easily done in graphics mode ( settextstyle ).
:

hah nevermind then. no problem




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.