Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit_Login;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
- type
- TfrmLogin = class(TForm)
- lbledtUsername: TLabeledEdit;
- lbledtPassword: TLabeledEdit;
- btnEnter: TButton;
- Exit: TButton;
- procedure btnEnterClick(Sender: TObject);
- procedure ExitClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- frmLogin: TfrmLogin;
- implementation
- uses
- Unit_AddLogin,UnitStudent_menu,Unit_TeacherMenu; //Allows access to the form add login and studnet menu
- {$R *.dfm}
- type
- TUsername = record //creating a record for the file to store usernames
- Username : string[20];
- end;
- type
- TPassword = record //creating a record for the file to store passwords.
- Password:string[20];
- end;
- var
- UsernameFile : File of TUsername;
- PasswordFile : File of Tpassword; // This will be the file whch stores the usernames
- New_username : array [1..1000] of Tusername; //An array used to store multiple usernames
- New_Password : array [1..1000] of TPassword; //An array used to store multiple Passwords
- procedure TfrmLogin.btnEnterClick(Sender: TObject);
- var
- count,counter,I,Temp_num : integer;
- begin
- {Code to check if teacher is trying to login in to the system}
- if (lbledtusername.Text = 'David.Searle') and (lbledtPassword.Text = 'Tudor') then //This is the hardcoded login detials for Mr Searl's account
- begin
- frmTeacherMenu.Show; //Shows the form where the teacher can create new users
- end;
- {Code to check if a student is logging in to the system}
- AssignFile(Usernamefile,'loginsave.dat'); //assigns exsiting file to New_usernamefile
- reset(UsernameFile); //opens the file
- AssignFile(PasswordFile ,'Password.dat'); //assigns exsiting file to New_Passwordfile
- reset(PasswordFile ); //opens the file
- count := 0; //intialises count
- while not Eof(Usernamefile) and not Eof (passwordfile) do {This will repeat the code below untill
- the end of file is reached}
- begin
- count := count + 1;
- Read(Usernamefile,New_username[count]); //reads the usernames from Usernamefile
- Read(Passwordfile,New_Password[count]); //reads the password from Passwordfile
- if (lbledtusername.Text = New_username[count].Username) and
- (lbledtPassword.Text = New_Password[count].Password) then
- begin
- frmStudentmenu.Show; //if the username is correct it shows the student menu
- end;
- end;
- Closefile(Usernamefile); //closes file which contains username
- Closefile(Passwordfile); //Closes file which contains passwords
- {Code to output incorrect login}
- I := 0;
- for counter := 1 to count do
- begin
- I := I + 1;
- if (lbledtusername.Text = New_username[I].Username) and
- (lbledtPassword.Text = New_Password[I].Password) then
- begin
- Temp_num:= I;
- end;
- end;
- //This checks that the user enters either teacher or student login
- if ((lbledtusername.Text <> New_username[temp_num].Username) or
- (lbledtPassword.Text <> New_Password[temp_num].Password)) and ((lbledtusername.Text <>
- 'David.Searle')or (lbledtPassword.Text <> 'Tudor')) then
- Showmessage('Incorrect Login');
- end;
- procedure TfrmLogin.ExitClick(Sender: TObject);
- begin
- close;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement