Closed Thread
Results 1 to 8 of 8

Thread: Password Program

  1. #1
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Password Program

    Hi I'm trying to add a login screen and user accounts to my program.

    Basically the variables for the username and password come from an ini file where the variables are defined. This is so the user can edit their username or password. When the user types in a username that is also in the ini file and a password that is also in the ini they will log in.

    However when I run my program and the user enters nothing in the Username or Password edit boxes they are logged in. When they enter the correct username and password are defined in the ini files or if they enter anything else they cant log in. Can someone help me I think its my code

    Heres the code for the ini File. Its stored in the same folder as the program and is called Password.ini

    Password.ini:
    [Users]
    Name=Alex
    [Pass]
    NPass=homepage
    Heres the code for the program. The parts in bold are the main lines relating to the either the ini File or the user and pass variables.
    unit Password;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, ExtCtrls, iniFiles;

    //uses iniFiles. The application uses iniFiles as part of the code.

    type
    TfrmPassword = class(TForm)
    ledtUsername: TLabeledEdit;
    ledtPassword: TLabeledEdit;
    btnOK: TButton;
    btnCancel: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    frmPassword: TfrmPassword;
    IniFile : TIniFile; //Defining IniFile as variable TIniFile.
    User : String; //Defining User as a string.
    Pass : String; //Defining Pass as a string.[/B]

    implementation

    uses Welcome;

    {$R *.dfm}

    procedure TfrmPassword.FormCreate(Sender: TObject);
    begin
    IniFile := TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));

    //Associates the ini File 'Password' with the application.
    User := IniFile.ReadString('Users','Name','');
    //User equals the variable Name in the users section of the ini file.
    Pass := IniFile.ReadString('Pass','NPass','');
    //Pass equals the variable NPass in the Pass section of the ini file.
    end;

    procedure TfrmPassword.btnOKClick(Sender: TObject);
    begin
    if ledtUsername.Text = User
    then
    if ledtPassword.Text = Pass
    then
    frmWelcome.show
    else
    ShowMessage ('Invalid Password.')
    else
    ShowMessage ('Invalid Username.');
    end;


    procedure TfrmPassword.btnCancelClick(Sender: TObject);
    begin
    close;
    end;
    Any help at all would be great. Thanks

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Password Program

    First thing I would do: showmessage(User) and showmessage(Pass) after reading in the values.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Join Date
    Dec 2008
    Posts
    2
    Rep Power
    0

    Re: Password Program

    Tried that, still have the same problem

  5. #4
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Password Program

    Well, are they set to the correct values? The issue is to isolate whether you are not reading the values from the ini file (which I suspect) or if you're not comparing them properly. If the issue is reading the values, then you need to look at whether the ini file is formatted correctly.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    ooisootuck is offline Learning Programmer
    Join Date
    Oct 2008
    Location
    Malaysia
    Posts
    36
    Rep Power
    0

    Re: Password Program

    You can always add watches or set a bread point, move your mouse over the variable when it's break will show the value.

    Thanks

  7. #6
    gasdeveloper is offline Newbie
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    2
    Rep Power
    0

    Re: Password Program

    I think that storing username and password in an ini file is a bad Idea to start with. One other problem I can see is that you will only be able to have one user at a time do to the layout and names of the variables in the ini file. if you don't want a standard SQL database or .mdb file with ADO Components try TuboPower Components B-TreeFiler.

  8. #7
    Rustix666's Avatar
    Rustix666 is offline Newbie
    Join Date
    Dec 2009
    Posts
    15
    Rep Power
    0

    Re: Password Program

    All looks good.
    Try to manually check variables:
    ledtUsername.Text
    ledtPassword.Text

    Also try to use Trim function.

  9. #8
    Firebird_38 is offline Programmer
    Join Date
    Aug 2008
    Posts
    126
    Rep Power
    0

    Re: Password Program

    Try:

    //Associates the ini File 'Password' with the application.
    User := IniFile.ReadString('Users','Name','This isn''t real');
    //User equals the variable Name in the users section of the ini file.
    Pass := IniFile.ReadString('Pass','NPass','This is also bogus');

    Then, if the ini isn't working, your values will make it so you can't log in unless you enter user "This isn't real" and password "This is also bogus".

    Also, you didn't state if you could log in using the defined user and pass, which I very strongly suspect you could not.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Password Changer program
    By sdanyal in forum Community Projects
    Replies: 3
    Last Post: 05-22-2011, 07:56 AM
  2. Program for password required access
    By didimus in forum C and C++
    Replies: 2
    Last Post: 12-11-2010, 04:41 AM
  3. PHP Password Encryption
    By phpforfun in forum PHP Development
    Replies: 8
    Last Post: 01-29-2010, 12:23 PM
  4. password
    By farzana in forum Visual Basic Programming
    Replies: 5
    Last Post: 12-30-2008, 11:57 AM
  5. Password
    By Lop in forum The Lounge
    Replies: 4
    Last Post: 07-02-2007, 11:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

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