943,724 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Oct 14th, 2008
0

text box as Username Entry - Not Listbox

Expand Post »
As part of my A-Level computing coursework i have to simulate an end user and design a programe for them.

I have the code to allow for a listbox were you select from a list of usernames you want but for added security i want to ammend it so you have to type in both the username and password (in text boxes) not just select one of the optional usernames (in the listbox). the code i have that works for the list box is as follows. Can anyone tell me how i can change my code so that you must type in the username?

for easy reading the username box is called TxtUsername and the password box is TxtPasword

thanks in advanced

my code is as follows:


Pascal and Delphi Syntax (Toggle Plain Text)
  1. unit RSPCA;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, ExtCtrls, StdCtrls, jpeg;
  8.  
  9. type
  10. TFrmRSPCALogin = class(TForm)
  11. BtnLogin: TButton;
  12. BtnExit: TButton;
  13. TxtPassword: TEdit;
  14. TxtUsername: TEdit;
  15. Image1: TImage;
  16. LblUsername: TLabel;
  17. Label1: TLabel;
  18. procedure BtnExitClick(Sender: TObject);
  19. procedure BtnLoginClick(Sender: TObject);
  20. procedure FormCreate(Sender: TObject);
  21. private
  22. { Private declarations }
  23. public
  24. { Public declarations }
  25. end;
  26.  
  27. var
  28. FrmRSPCALogin: TFrmRSPCALogin;
  29.  
  30. implementation
  31.  
  32.  
  33. type
  34.  
  35. Tuser = record
  36. s_Username : string;
  37. s_Password : string;
  38. i_type : integer;
  39.  
  40. end;
  41.  
  42. const
  43. USERS = 'Users.txt';
  44. SETTINGS = 'Settings.txt';
  45.  
  46. var
  47. a_user : array [0..15] of TUser;
  48. i_logins : integer;
  49. i_maxlogins : integer;
  50.  
  51. {$R *.dfm}
  52.  
  53. procedure TFrmRSPCALogin.BtnExitClick(Sender: TObject);
  54. begin
  55. Application.Terminate;
  56. end;
  57.  
  58. procedure TFrmRSPCALogin.BtnLoginClick(Sender: TObject);
  59. var
  60. fp_settings : textFile;
  61. begin
  62. inc(i_logins);
  63.  
  64. if i_logins > i_maxlogins then
  65. begin
  66. messagedlg('To many Login Attempts, Program Is Now Locked!', mtError, [mbOk], 0);
  67.  
  68. AssignFile(fp_settings, SETTINGS);
  69. Rewrite(fp_settings);
  70.  
  71. WriteLn(fp_settings, '1');
  72. WriteLn(fp_settings, InttoStr(i_maxlogins));
  73.  
  74. CloseFile(fp_settings);
  75.  
  76. Application.terminate;
  77. end else
  78. begin
  79. if Uppercase(trim(TxtPassword.Text)) =
  80. Uppercase(trim(a_User[TxtUsername.ItemIndex].s_password)) then
  81. begin
  82. s_username := a_user[LstUsers.Itemindex.s_Username;
  83. FrmPassword.Hide;
  84. Application.CreateForm(TFrmMain, FrmMain);
  85. FrmMain.Show;
  86. end else
  87. begin
  88. MessageDlg('Wrong Password!', mtError, [mbOk], 0);
  89. TxtPassword.Clear;
  90. TxtPassword.setFocus;
  91. end;
  92. end;
  93. end;
  94. procedure TFrmRSPCALogin.FormCreate(Sender: TObject);
  95. var
  96. fp_users : Textfile;
  97. fp_settings : Textfile;
  98. i_users : integer;
  99. s_temp : string;
  100.  
  101. begin
  102. if FileExists(SETTINGS) then
  103. begin
  104. AssignFile(fp_settings, SETTINGS);
  105. reset(fp_Settings);
  106.  
  107. ReadLn(fp_settings, s_temp);
  108. if s_temp <> '0' then
  109. begin
  110. MessageDlg('Program is Locked!', mtError, [mbOk], 0);
  111. Application.terminate;
  112. end else
  113. begin
  114. ReadLn(fp_settings, s_temp);
  115. i_maxlogins := StrToInt(s_temp);
  116. end;
  117. CloseFile(fp_settings);
  118. end else
  119. begin
  120. MessageDlg('Missing Settings Files!', mterror, [mbOk], 0);
  121. Application.terminate;
  122. end;
  123. if FileExists (USERS) then
  124. begin
  125. AssignFile(fp_users, USERS);
  126. Reset(fp_USERRS);
  127.  
  128. i_users := 0;
  129.  
  130. while not EOF(fp_users) do
  131. begin
  132. ReadLn(fp_Uers, a_user[i_users].s_username);
  133. LstUsers.items.Add(a_user[i_users].s_username);
  134. ReadLn(fp_Users, a_user[i_users].s_password);
  135.  
  136. ReadLn(fp_users, s_temp);
  137. a_User[i_users].i_type := StrToInt(s_temp);
  138.  
  139. inc(i_users);
  140. end;
  141.  
  142. closeFile(fp_users);
  143. end;i_logins :=0;
  144.  
  145. end else
  146. begin;
  147. MessageDlg('Password File does not exist!', mtError, [mbOk], 0);
  148. Application.terminate;
  149. end;
  150. end;
  151.  
  152.  
  153.  
  154. end.
Last edited by Kev_McG; Oct 14th, 2008 at 12:06 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kev_McG is offline Offline
6 posts
since Oct 2008
Oct 14th, 2008
0

Re: text box as Username Entry - Not Listbox

I'm not sure of your intent. I visualize three compnents on the form, the list box with the user names, and two text boxes, one for names and one for passwords. IF you have a listbox that has read the nnames, then it is a simple matter for the user to copy it over to the textbox. Are you trying to keep the list of names private or visible? Please expand upon what you are attempting to do here
Reputation Points: 11
Solved Threads: 11
Junior Poster in Training
jsosnowski is offline Offline
68 posts
since Nov 2007
Oct 15th, 2008
0

Re: text box as Username Entry - Not Listbox

Change it to a text box, and then as part of the check, check that the contents of that box is in the valid usernames list.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Oct 16th, 2008
0

Re: text box as Username Entry - Not Listbox

Click to Expand / Collapse  Quote originally posted by jsosnowski ...
I'm not sure of your intent. I visualize three compnents on the form, the list box with the user names, and two text boxes, one for names and one for passwords. IF you have a listbox that has read the nnames, then it is a simple matter for the user to copy it over to the textbox. Are you trying to keep the list of names private or visible? Please expand upon what you are attempting to do here

on my login screen i have 2 boxes, both text boxes one for username one for password, how ever the code given to me to modify to fit my own form names etc by my teacher was that of a login screen using a list box were you just select the username and enter the password. i want it so you have NO list box but in its place have an edit box were you manually enter the username
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kev_McG is offline Offline
6 posts
since Oct 2008
Oct 16th, 2008
0

Re: text box as Username Entry - Not Listbox

I think I answered your question. You just chose to ignore me.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Oct 16th, 2008
0

Re: text box as Username Entry - Not Listbox

Click to Expand / Collapse  Quote originally posted by LizR ...
I think I answered your question. You just chose to ignore me.
i didnt ignore you, what you said jsut wasnt to helpful to me, please bare in mind im a student and im not great at programming to start with. the line i seem to be getting most of my problems on is

"Uppercase(trim(a_User[TxtUsername.ItemIndex].s_password)) then"

i still have no idea how to fix it or what to type in place of the rest of the code.

as you can tell my teacher isnt the best ^^
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kev_McG is offline Offline
6 posts
since Oct 2008
Oct 17th, 2008
0

Re: text box as Username Entry - Not Listbox

Or as a student, perhaps you arent asking him the right questions, as with me, you didnt say "oh, I dont see how I'd do that" you just ignored it.. perhaps you do the same to him?

Anyway.

Do you have understanding as to what the line
Pascal and Delphi Syntax (Toggle Plain Text)
  1. Uppercase(trim(a_User[TxtUsername.ItemIndex].s_password))
does?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Oct 17th, 2008
0

Re: text box as Username Entry - Not Listbox

to my knowledge, if im correct that line should allow the program to ignore differences between upper and lower case characters in the password how ever when the code was given to me i did previously have this

Pascal and Delphi Syntax (Toggle Plain Text)
  1. Uppercase(trim(a_User[LstUsername.ItemIndex].s_password))

the difference being ive changed it from "LstUsername" to "TxtUsername" although i tried changing it back and adding in the list box with that name instead and it still didnt work ^^
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kev_McG is offline Offline
6 posts
since Oct 2008
Oct 17th, 2008
0

Re: text box as Username Entry - Not Listbox

So you dont even know what the line does then..

I would suggest you go back to your teacher, as that line of code is far from complex if you have failed to understand, either the guy is a complete moron, or you didnt listen. Or some percentage of the 2.

If you changed the TxtUserName (and assuming its an editbox) then that code shouldnt have compiled as editboxes dont have an itemindex.

If you struggle with something as simple as breaking down some code you were given try working through this free online training course

Its not perfect but it should teach you more than you seem to already know
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Oct 17th, 2008
0

Re: text box as Username Entry - Not Listbox

i know something is wrong with that line but the teacher i have jsut says, to do what you want will require different code... which i know but he wont help me write the different code, hence why im here. i know that itemindex is wrong, i pretty much figured it was that phrase there to start with. and if that line doesnt do what i stated then its my teacher who is wrong as thats what i was told.

rather than beating around the bush if you can see whats wrong with it could you not be less pedantic and correct it for me? save us all the hassle. after all that is why i posted this thread, to get help correcting it.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kev_McG is offline Offline
6 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Debugger ignors one line in source code
Next Thread in Pascal and Delphi Forum Timeline: Error 207:Invalid floating point operation??? in Turbo PASCAL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC