Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Password Program


  • Please log in to reply
7 replies to this topic

#1 dejongajongjong

dejongajongjong

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 23 December 2008 - 01:43 PM

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 :)
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 23 December 2008 - 07:28 PM

First thing I would do: showmessage(User) and showmessage(Pass) after reading in the values.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 dejongajongjong

dejongajongjong

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 24 December 2008 - 02:15 AM

Tried that, still have the same problem :(
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 24 December 2008 - 03:51 AM

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.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 ooisootuck

ooisootuck

    CC Regular

  • Just Joined
  • PipPipPip
  • 29 posts

Posted 03 January 2009 - 04:55 AM

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
  • 0

#6 gasdeveloper

gasdeveloper

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 20 January 2009 - 03:46 PM

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.
  • 0

#7 Rustix666

Rustix666

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 10 December 2009 - 03:53 AM

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

Also try to use Trim function.
  • 0

#8 Firebird_38

Firebird_38

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 117 posts

Posted 07 January 2010 - 11:10 AM

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.
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download