| | |
text box as Username Entry - Not Listbox
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
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:
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)
unit RSPCA; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, jpeg; type TFrmRSPCALogin = class(TForm) BtnLogin: TButton; BtnExit: TButton; TxtPassword: TEdit; TxtUsername: TEdit; Image1: TImage; LblUsername: TLabel; Label1: TLabel; procedure BtnExitClick(Sender: TObject); procedure BtnLoginClick(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var FrmRSPCALogin: TFrmRSPCALogin; implementation type Tuser = record s_Username : string; s_Password : string; i_type : integer; end; const USERS = 'Users.txt'; SETTINGS = 'Settings.txt'; var a_user : array [0..15] of TUser; i_logins : integer; i_maxlogins : integer; {$R *.dfm} procedure TFrmRSPCALogin.BtnExitClick(Sender: TObject); begin Application.Terminate; end; procedure TFrmRSPCALogin.BtnLoginClick(Sender: TObject); var fp_settings : textFile; begin inc(i_logins); if i_logins > i_maxlogins then begin messagedlg('To many Login Attempts, Program Is Now Locked!', mtError, [mbOk], 0); AssignFile(fp_settings, SETTINGS); Rewrite(fp_settings); WriteLn(fp_settings, '1'); WriteLn(fp_settings, InttoStr(i_maxlogins)); CloseFile(fp_settings); Application.terminate; end else begin if Uppercase(trim(TxtPassword.Text)) = Uppercase(trim(a_User[TxtUsername.ItemIndex].s_password)) then begin s_username := a_user[LstUsers.Itemindex.s_Username; FrmPassword.Hide; Application.CreateForm(TFrmMain, FrmMain); FrmMain.Show; end else begin MessageDlg('Wrong Password!', mtError, [mbOk], 0); TxtPassword.Clear; TxtPassword.setFocus; end; end; end; procedure TFrmRSPCALogin.FormCreate(Sender: TObject); var fp_users : Textfile; fp_settings : Textfile; i_users : integer; s_temp : string; begin if FileExists(SETTINGS) then begin AssignFile(fp_settings, SETTINGS); reset(fp_Settings); ReadLn(fp_settings, s_temp); if s_temp <> '0' then begin MessageDlg('Program is Locked!', mtError, [mbOk], 0); Application.terminate; end else begin ReadLn(fp_settings, s_temp); i_maxlogins := StrToInt(s_temp); end; CloseFile(fp_settings); end else begin MessageDlg('Missing Settings Files!', mterror, [mbOk], 0); Application.terminate; end; if FileExists (USERS) then begin AssignFile(fp_users, USERS); Reset(fp_USERRS); i_users := 0; while not EOF(fp_users) do begin ReadLn(fp_Uers, a_user[i_users].s_username); LstUsers.items.Add(a_user[i_users].s_username); ReadLn(fp_Users, a_user[i_users].s_password); ReadLn(fp_users, s_temp); a_User[i_users].i_type := StrToInt(s_temp); inc(i_users); end; closeFile(fp_users); end;i_logins :=0; end else begin; MessageDlg('Password File does not exist!', mtError, [mbOk], 0); Application.terminate; end; end; end.
Last edited by Kev_McG; Oct 14th, 2008 at 12:06 pm.
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
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
•
•
•
•
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
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
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 ^^
"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 ^^
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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
does?
Anyway.
Do you have understanding as to what the line
Pascal and Delphi Syntax (Toggle Plain Text)
Uppercase(trim(a_User[TxtUsername.ItemIndex].s_password))
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.
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
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
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 ^^
Pascal and Delphi Syntax (Toggle Plain Text)
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 ^^
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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
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.
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
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.
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.
![]() |
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Debugger ignors one line in source code
- Next Thread: Error 207:Invalid floating point operation??? in Turbo PASCAL
| Thread Tools | Search this Thread |






