Solved

juz Debugging!

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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