Solved

juz Debugging!

Posted on 1998-06-16
4
157 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

22 Experts available now in Live!

Get 1:1 Help Now