Password program

FlamingClaw 0 Tallied Votes 2K Views Share

This is just a simple password program...

Program Password_Program;

{used moduls}
Uses Crt;

{Declare variables}
Var  Password,User:String[11];
     Count,i:Byte;


Begin {main}
     Password:='123-456-78';
     Count:=3;
     ClrScr; {ClearScreen}
     For i:=3 DownTo 1 Do
        Begin
           Write(i:2,'.Give Me The Password: ');
           ReadLn(User);{catch the user password}
           If (User <> Password) Then {analize it}
              Begin
                 WriteLn('Error!');
                 Count:=Count-1;
                 If (Count=0)Then
                   Begin   {if count reaches 0 then exit}
                      WriteLn('Access Deined!');
                      ReadKey;
                      Halt;
                   End;
                 Continue;  {if not good,ask again}
              End
           Else Begin
                   WriteLn('Ok.');
                   Break;  {if good breaking loop}
                End;
        End;
     WriteLn('Have a nice day...');
     ReadLn;
End. {main}
{
-=Note By FlamingClaw=-
This is just a simple password program...
-=Created By FlamingClaw=-
2009.03.16.
}
mahmoud85 0 Newbie Poster

hi, am mahmoud85 i new member in this forum
thank you for this code

FreeBirdLjj 0 Newbie Poster

But I have a suggestion:other password input program will use "*" in stead of the char which you input.And you can use the function "ReadKey"(in CRT unit) which gets a char from keyboard and doesn't show this char in screen.

Uses CRT;{I only give you the UI codes and you can use it after reading}
Var
 Password,s:String;
 ch:Char;
 i,j:Integer;
Begin
 i:=0;
 Repeat
  ch:=ReadKey;
  If ch in ['0'..'9','a'..'z','A'..'Z','!','@','#','$','%','^','&','*','(',')','-','=','_','+','\','|','/','?','''','"',';',':',',','.','<','>','[',']']
   Then
    Begin
     Write('*');
     i:=i+1;
     s[i]:=ch;
    End;
  If Ord(ch)=8{ch=BackSpace}
   Then
    Begin
     i:=i-1;
     GotoXY(GetY,i+1);
     Write(' ');
    End;
 Until Ord(ch)=13;{ch=Enter}
 For j:=1 to i do
  Password[j]:=s[j];
End;
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.