Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- nit 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);
- procedure FormCreate(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
- TPassword = record //creating a record for the file to store passwords.
- Password : string[20];
- end;
- Type
- TStudentNumber = record
- StudentNumber : String[6];
- end;
- var
- PasswordFile : File of Tpassword; // This will be the file whch stores the usernames
- StudentNumberFile : File of TStudentNumber;
- New_Password : array [1..1000] of TPassword; //An array used to store multiple Passwords
- New_StudentNumber : array [1..1000] of TStudentNumber;
- Path : String;
- procedure TfrmLogin.btnEnterClick(Sender: TObject);
- var
- count,counter,I,Temp_num : integer;
- Correct : Boolean;
- CurrentFile : TextFile;
- 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;
- AssignFile(PasswordFile ,Path +'Password.dat'); //assigns exsiting file to Passwordfile
- reset(PasswordFile ); //opens the file
- AssignFile(StudentNumberFile ,Path +'StudentNumber.dat'); //assigns exsiting file to StudentNumberFile
- reset(StudentNumberFile );
- count := 0; //intialises count
- while not eof (StudentNumberFile) and not Eof (passwordfile) do
- {This will repeat the code below untill the end of file is reached}
- begin
- count := count + 1;
- Read(Passwordfile,New_Password[count]); //reads the password from Passwordfile
- Read(StudentNumberFile,New_StudentNumber[count]);
- if ((lbledtusername.Text = New_StudentNumber[count].StudentNumber) and
- (lbledtPassword.Text = New_Password[count].Password)) then
- begin
- frmStudentmenu.Show; //if the login credentials is correct it shows the student menu
- end;
- end;
- CloseFile(Passwordfile); //Closes file which contains passwords
- CloseFile(StudentNumberFile);
- {Code to output incorrect login}
- I := 0;
- for counter := 1 to count do
- begin
- I := I + 1;
- if (lbledtusername.Text = New_StudentNumber[I].StudentNumber) and
- (lbledtPassword.Text = New_Password[I].Password) then
- begin
- Temp_num:= I;
- end;
- end;
- Correct := True;
- if ((lbledtusername.Text <> New_StudentNumber[temp_num].StudentNumber)) then
- begin
- Correct := False;
- end;
- //This checks that the user enters either teacher or student login
- if ((Correct = False) and
- (lbledtPassword.Text <> New_Password[temp_num].Password)) and ((lbledtusername.Text <>
- 'David.Searle')or (lbledtPassword.Text <> 'Tudor')) or (lbledtPassword.Text = '') or
- (lbledtUsername.Text = '')then
- begin
- Showmessage('Incorrect Login');
- end;
- AssignFile(CurrentFile,'CurrentUser.txt'); //assigns exsiting file to New_usernamefile
- ReWrite(CurrentFile); //opens the file
- Writeln(CurrentFile,New_StudentNumber[Temp_num].StudentNumber);
- Writeln(CurrentFile,New_Password[Temp_num].Password);
- CloseFile(CurrentFile);
- end;
- procedure TfrmLogin.ExitClick(Sender: TObject);
- begin
- close;
- end;
- procedure TfrmLogin.FormCreate(Sender: TObject);
- var
- count : integer;
- begin
- Count := Count + 1;
- if Count = 1 then
- begin
- Path := GetCurrentDir;
- Count := 2;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement