Solved

juz Debugging!

Posted on 1998-06-16
4
160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 153
Tembedded WB animatid gifs not animated on some pcs 2 92
Firemonkey DbLookupComboBox equivalent ? 2 77
Using MMsystem To change audio input 1 37
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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