text box as Username Entry - Not Listbox

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 6
Reputation: Kev_McG is an unknown quantity at this point 
Solved Threads: 0
Kev_McG Kev_McG is offline Offline
Newbie Poster

text box as Username Entry - Not Listbox

 
0
  #1
Oct 14th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 68
Reputation: jsosnowski is an unknown quantity at this point 
Solved Threads: 11
jsosnowski's Avatar
jsosnowski jsosnowski is offline Offline
Junior Poster in Training

Re: text box as Username Entry - Not Listbox

 
0
  #2
Oct 14th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: text box as Username Entry - Not Listbox

 
0
  #3
Oct 15th, 2008
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.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: Kev_McG is an unknown quantity at this point 
Solved Threads: 0
Kev_McG Kev_McG is offline Offline
Newbie Poster

Re: text box as Username Entry - Not Listbox

 
0
  #4
Oct 16th, 2008
Originally Posted by jsosnowski View Post
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: text box as Username Entry - Not Listbox

 
0
  #5
Oct 16th, 2008
I think I answered your question. You just chose to ignore me.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: Kev_McG is an unknown quantity at this point 
Solved Threads: 0
Kev_McG Kev_McG is offline Offline
Newbie Poster

Re: text box as Username Entry - Not Listbox

 
0
  #6
Oct 16th, 2008
Originally Posted by LizR View Post
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 ^^
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: text box as Username Entry - Not Listbox

 
0
  #7
Oct 17th, 2008
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?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: Kev_McG is an unknown quantity at this point 
Solved Threads: 0
Kev_McG Kev_McG is offline Offline
Newbie Poster

Re: text box as Username Entry - Not Listbox

 
0
  #8
Oct 17th, 2008
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 ^^
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: text box as Username Entry - Not Listbox

 
0
  #9
Oct 17th, 2008
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
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: Kev_McG is an unknown quantity at this point 
Solved Threads: 0
Kev_McG Kev_McG is offline Offline
Newbie Poster

Re: text box as Username Entry - Not Listbox

 
0
  #10
Oct 17th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC