Results 1 to 4 of 4

Thread: Login :@

  1. #1
    Join Date
    Jun 2007
    Posts
    47

    Login :@

    My login wont work..

    I have two apps, one is for making a login file that saves username and password, the other reads from file; checks text in edit boxs to find match. It all works fine but now im tryin to add an encrytion on the password.

    Code:
    Var   output: array[1..10] of char;
            i:integer;
    
    for i:=1 to length(EDTPassword.Text) do
           begin
            output[i] := CHAR(ORD(EDTPassword.Text[i])+ 3);
           end;
    So the password abc is saved on file as def, i have the same code so when the user tries to login they enter abc in EDTpassword, output is now def, and checked on file. But i doesnt login

    Ive done a showmessage(output); its def.. look in the file and password is save as def.

  2. #2
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    Ok, but there isnt enough there to show the checking as to why it thinks its not the same, that shows some of the encryption part, but is it actually returning the encryption? We cant tell from that.
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  3. #3
    Join Date
    Jun 2007
    Posts
    47
    Unit for seting up account

    Code:
    unit UNTlogin;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Mask;
    
    Const Loginfilename = 'G:\login.dat';
    
    type  TFRMLoginApp = class(TForm)..
        
    Type      Tlogin = record
              Username ,email:string[30];
              Password:string[10];
              Level:integer;
    end;
    
    TYPE      TLoginfile = File of TLogin;
    
    var
      FRMLoginApp:TFRMLoginApp;
      LoginRec:TLogin;
      loginFile:TLoginFile;
      output:array[1..10] of char;
    
    implementation
    
    {$R *.dfm}
    
    procedure TFRMLoginApp.FormCreate(Sender: TObject);
    begin
     AssignFile(LoginFile,'G:\Login.dat');
     Rewrite(LoginFile);
    end;
    
    procedure TFRMLoginApp.BTNWritetofileClick(Sender: TObject);
    
    var i:integer;
    
    begin
    loginrec.username := EDTUsername.Text;
    
    //*********start encryption******************
    for i:= 1 to length(EDTPassword.Text) do
      begin
      output[i] := CHAR(ORD(EDTPassword.Text[i])+ 3);
     end;
    //*********end encryption*******************
    
    loginrec.Password := output;
    loginrec.Level := strtoint(EDTAccountlevel.Text);
    loginrec.email := EDTemail.Text;
    
    write(loginfile, loginrec);
    end;
    
    procedure TFRMLoginApp.BTNExitClick(Sender: TObject);
    begin
    close;
    closefile(loginfile);
    end;
    
    end.
    Unit for login to account

    Code:
    unit UntBasketball;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, ActnList, Menus, Tabs, ComCtrls, jpeg,
      IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
      IdMessageClient, IdSMTP, IdMessage;
    
    Const Loginfilename = 'G:\login.dat';
    
    type  TFRMMain = class(TForm)..
        
    TYPE        Tlogin = record
                Username, email:string[30];
                Level:integer;
                Password:string[10];
    end;
    
    TYPE      TLoginfile = File of TLogin;
    
    var  FRMMain  :TFRMMain;
         LoginRec :TLogin;
         LoginFile:TLoginFile;
         Flag:integer;
         check, check1:boolean;
         output: array[1..10] of char;
    
    Implementation
    {$R *.dfm}
    
    Procedure TFRMMain.BTNLoginClick(Sender: TObject);
    
    var      i:integer;
    
    Begin
    Flag := 0;
    check := false;
     If Flag = 0 then begin
     AssignFile(LoginFile,'G:\Login.dat');
     Reset(LoginFile);
     seek(loginfile, 0 );
     While NOT EoF(loginfile) do
      Begin
       read(loginfile, loginrec);
    
         for i:=1 to length(EDTPassword.Text) do
             begin
               output[i] := CHAR(ORD(EDTPassword.Text[i])+ 3);
             end;
    
         if EDTUsername.Text = loginrec.Username then
         if output = loginrec.Password then
    
          Begin
            if loginrec.level = 0 then
              begin
                check := true;
                Flag:=1;
                BTNAdmin.Visible := true;
                BTNCoach.Enabled := true;
                BTNTeam.Enabled := true;
                BTNLogin.Visible := false;
                BTNlogout.Visible := true;
                EDTusername.color :=  clBtnShadow;
                EDTusername.readonly := true;
                EDTpassword.color :=  clBtnShadow;
                EDTpassword.readonly := true;
                FRMMain.ClientHeight := 315;
                lblforgot.Enabled := false;
              end;
            if loginrec.level = 1 then
              begin
               Flag:=1;
               check := true;
               BTNCoach.Enabled := true;
               BTNTeam.Enabled := true;
               BTNLogin.Visible := false;
               BTNlogout.Visible := true;
               EDTusername.color :=  clBtnShadow;
               EDTusername.readonly := true;
               EDTpassword.color :=  clBtnShadow;
               EDTpassword.readonly := true;
               lblforgot.Enabled := false;
              end;
            if loginrec.level = 2 then
              begin
               check := true;
               Flag:=1;
               BTNTeam.Enabled := true;
               BTNLogin.Visible := false;
               BTNlogout.Visible := true;
               EDTusername.color :=  clBtnShadow;
               EDTusername.readonly := true;
               EDTusername.color :=  clBtnShadow;
               EDTusername.readonly := true;
               EDTpassword.color :=  clBtnShadow;
               EDTpassword.readonly := true;
               lblforgot.Enabled := false;
              end;
          end;
    
    end;
       end;
    
    closefile(loginfile);
    if check = false then
    Application.MessageBox('Invalid Username/Password!','Warning',MB_ICONEXCLAMATION);
    end;
    Last edited by $eymour; 10-07-2007 at 03:33 PM.

  4. #4
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    That code is very confusing, with all the duplication and unnecessary bits.

    But the simple error seems to be you arent comparing the password they entered after you encrypt it, you're testing what they entered.
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •