Solved

juz Debugging!

Posted on 1998-06-16
4
156 Views
Last Modified: 2010-04-04
well.. this is basically my password form and my change password form

 the password form is bascially decrypting an encrypted password from a file
and then comparing with the user's input thru an edit box
 
the change password form is where i change my password
thru 1st entering the correct password(of which there are 2)
then entering the new password
and reentering to confirm

LP and TP are representations of the 2 passwords

my question is..
Can someone debug this and tell me what';s wrong
and show me excatly by tellin me where to change and change to what or otherwise can u offer any
other solutions that does the same function?

Good luck!
and thanx for looking!


PASSWORD FORM

const
  C1 = 52845;
  C2 = 22719;
Var CountTries : Integer ;

{$R *.DFM}
function Encrypt(const S: String; Key: Word): String;
var
  I: byte;
begin
  Result := S;
  for I := 1 to Length(S) do begin
    Result[I] := char(byte(S[I]) xor (Key shr 8));
//    Key := (byte(Result[I]) + Key) * C1 + C2;
  end;
end;

function Decrypt(const S: String; Key: Word): String;
var
  I: byte;
begin
  Result := S ;
  for I := 1 to Length(S) do begin
    Result[I] := char(byte(S[I]) xor (Key shr 8));
//    Key := (byte(S[I]) + Key) * C1 + C2;
  end;
end;

procedure TPassForm.OKClick(Sender: TObject);
Const
   PasswordConst : Word = 12345;
var
  PassIni : TIniFile;
  LP , TP , CurPass : String;
  MaxTries : Integer ;
begin
   PassIni := TIniFile.Create ( 'C:\Library\Pass.Ini' );
   LP := Decrypt ( PassIni.ReadString ( 'Standard' , 'LP' , 'librarian' ) , PasswordConst ) ;
   TP := Decrypt ( PassIni.ReadString ( 'Standard' , 'TP' , 'teacher' ) , PasswordConst ) ;
   MaxTries := PassIni.ReadInteger ( 'Standard' , 'MT' , 5 );
   If ( Edit1.Text = LP ) Then
   Begin
      PassForm.Hide ;

      main.caption:= 'Anglo-Chinese Library™ ( Librarian MODE)';
      Main.Tasks1.enabled:=True ;
      Main.StudentInformation1.enabled:=True ;
      Main.Exit1.Enabled:=True;
      Showmessage(' Identity Validated as Librarian') ;
      PassIni.Free;
   End
   Else
   If ( Edit1.Text = TP ) Then
   Begin
      PassForm.Hide ;

      main.caption:= 'Anglo-Chinese Library™ ( Manager MODE)';
      Main.Tasks1.enabled:=True ;
      Main.Manager1.enabled:=True ;
      Main.StudentInformation1.enabled:=True ;
      Main.Exit1.Enabled:=True;
      Showmessage(' Identity Validated as Teacher') ;
      PassIni.Free;
   End
   Else
   Begin
      Inc ( CountTries );
      If CountTries > MaxTries Then
      Begin
         Beep ;
         Showmessage('Please Check your Password or consult your Manager for advice');

         Main.Tasks1.enabled:=False ;
         Main.Manager1.enabled:=False ;
         Main.StudentInformation1.enabled:=False ;
         Main.Exit1.Enabled:=False;
         PassForm.Hide ;
         PassIni.Free;
      End;
   End;
end;


procedure TPassForm.CancelClick(Sender: TObject);
begin

Close ;

end;



procedure TPassForm.FormActivate(Sender: TObject);
begin
   CountTries := 0 ;
end;


my Change password FORm

procedure TChangePass.BitBtn1Click(Sender: TObject);
Const
   PasswordConst : Word = 12345;
var
  PassIni : TIniFile;
  LP , TP , CurPass : String;
  MaxTries : Integer ;
begin
   PassIni := TIniFile.Create ( 'C:\Library\Pass.Ini' );

   IF (edit1.Text<>LP) or (edit1.text<>TP) then begin
   showmessage('Please Check Your Password!')
     end
   else


    IF (edit1.Text=LP) then begin

    If (edit2.Text='') or (edit3.Text='') then begin
    ShowMessage('Please Fill in your Desired password and Reenter it again for Checking');
     end
    else
    If edit2.Text<>edit3.Text then begin
    ShowMessage('Checking Failed! Please ReEnter New Password ');
     end
    else
    begin
    PassIni.WriteString ( 'Standard' , 'LP' , Encrypt ( Edit2.Text , PasswordConst ) );
    PassIni.Free;
     end ;




    IF (edit1.Text=TP) then begin

    If (edit2.Text='') or (edit3.Text='') then begin
    ShowMessage('Please Fill in your Desired password and Reenter it again for Checking');
     end
    else
    If edit2.Text<>edit3.Text then begin
    ShowMessage('Checking Failed! Please ReEnter New Password ');
     end
    else
    begin
    PassIni.WriteString ( 'Standard' , 'TP' , Encrypt ( Edit2.Text , PasswordConst ) );
    PassIni.Free;
     end



0
Comment
Question by:darkwing
4 Comments
 
LVL 4

Expert Comment

by:d003303
ID: 1353020
Yo,
you can use the UpperCase function to first put the password in upper case before encrypting or validating it.
In the procedure
TChangePass.BitBtn1Click(Sender: TObject);
I did not understand the
IF (edit1.Text<>LP) or (edit1.text<>TP) then begin
line, because LP and TP are not initialized with any string value. Maybe this is the point.

Slash/d003303
0
 
LVL 3

Expert Comment

by:vladika
ID: 1353021
In the procedure TPassForm.OKClick(Sender: TObject)
if  Edit1.Text <> LP and  Edit1.Text <> TP and CountTries <= MaxTries
you did not FREE PassIni.
To ensure that you free allocated resources you should use  try .. finally block
PassIni := TIniFile.Create ( 'C:\Library\Pass.Ini' );
try
  ...............
finally
  PassIni.Free;
end;

0
 

Author Comment

by:darkwing
ID: 1353022
Edited text of question
0
 
LVL 2

Accepted Solution

by:
hrizal earned 200 total points
ID: 1353023
to give highspeed response
try move procedure OKClick to
event onchange in editbox
so you can debug char by char
0

Featured Post

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.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now