Solved

juz Debugging!

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Graphic and Text to Epson TM-T88v 12 264
Magic Software info 18 132
CheckListBox usage 3 59
Slow Restore if incremental backups using RDiff.exe 4 21
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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