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);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- Type
- TPassword = record //creating a record for the file to store passwords.
- StudentPassword : string[20];
- end;
- Type
- TStudentNumber = record
- StudentNumber : String[6];
- end;
- Type
- TTeacherUser = record
- TeacherUsername : String[25];
- end;
- Type
- TTeacherPassword = record
- TeacherPassword : String[25];
- end;
- var
- //Variables for Student accounts
- PasswordFile : File of Tpassword; // This will be the file whch stores the usernames
- StudentNumberFile : File of TStudentNumber;
- Student_Password : array [0..1000] of TPassword; //An array used to store multiple Passwords
- Student_Number : array [0..1000] of TStudentNumber;
- //Variabels for teacher account
- TeacherUsernameFile : File of TTeacherUser;
- TeacherPasswordFile : File of TTeacherPassword;
- Teacher_Username : array [0..1000] of TTeacherUser;
- Teacher_Password : array [0..1000] of TTeacherPassword ;
- FinalStudent,FinalTeacher : Integer;
- end;
- var
- frmLogin: TfrmLogin;
- implementation
- uses
- Unit_AddLogin,UnitStudent_menu,Unit_TeacherMenu; //Allows access to the form add login and studnet menu
- {$R *.dfm}
- var
- Path : String;
- procedure TfrmLogin.btnEnterClick(Sender: TObject);
- var
- count,counter,I,Temp_num : integer; //Variables for Student account
- N,Current,Counts : Integer; //Variables for Teacher accounts
- StudentCorrect,TeacherCorrect : Boolean;
- begin
- //Reads the username and password file for students
- 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
- Read(Passwordfile,Student_Password[count]); //reads the password from Passwordfile
- Read(StudentNumberFile,Student_Number[count]);
- if ((lbledtusername.Text = Student_Number[count].StudentNumber) and
- (lbledtPassword.Text = Student_Password[count].StudentPassword)) then
- begin
- Showmessage('Login Successful');
- frmStudentmenu.Show; //if the login credentials is correct it shows the student menu
- end;
- count := count + 1;
- end;
- CloseFile(Passwordfile); //Closes file which contains passwords
- CloseFile(StudentNumberFile);
- {Code to output incorrect login}
- I := 0;
- for counter := 0 to count do
- begin
- I := I + 1;
- if (lbledtusername.Text = Student_Number[I].StudentNumber) and
- (lbledtPassword.Text = Student_Password[I].StudentPassword) then
- begin
- Temp_num:= I;
- end;
- end;
- StudentCorrect := True;
- if ((lbledtusername.Text <> Student_Number[temp_num].StudentNumber)) then
- begin
- StudentCorrect := False;
- end;
- //Read from the teacher's Username and Password file
- AssignFile(TeacherPasswordFile ,Path +'TeacherPassword.dat'); //assigns exsiting file to Passwordfile
- reset(TeacherPasswordFile); //opens the file
- AssignFile(TeacherUserNameFile ,Path +'TeacherUser.dat'); //assigns exsiting file to StudentNumberFile
- reset(TeacherUserNameFile);
- counts := 0; //intialises count
- while not eof (TeacherUserNameFile) and not Eof (TeacherPasswordFile) do
- {This will repeat the code below untill the end of file is reached}
- begin
- Read(TeacherPasswordfile,Teacher_Password[counts]); //reads the password from Passwordfile
- Read(TeacherUsernameFile,Teacher_Username[counts]);
- if ((lbledtusername.Text = Teacher_Username[counts].TeacherUsername) and
- (lbledtPassword.Text = Teacher_Password[counts].TeacherPassword)) then
- begin
- Showmessage('Login Successful');
- frmTeachermenu.Show; //if the login credentials is correct it shows the student menu
- end;
- counts := counts + 1;
- end;
- CloseFile(TeacherPasswordfile); //Closes file which contains passwords
- CloseFile(TeacherUserNameFile);
- N := 0;
- for counter := 0 to counts do
- {This checks to see if the account credntials match the ones stored in the system }
- begin
- if (lbledtusername.Text = Teacher_Username[N].TeacherUsername) and
- (lbledtPassword.Text = Teacher_Password[N].TeacherPassword) then
- begin
- Current:= N;
- end;
- N := N + 1;
- end;
- TeacherCorrect := True;
- if ((lbledtusername.Text <> Teacher_Username[N].TeacherUsername)) then
- begin
- TeacherCorrect := False;
- end;
- //This checks that the user enters either teacher or student login
- if ((StudentCorrect = False) or (TeacherCorrect = False) and
- (lbledtPassword.Text <> Student_Password[temp_num].StudentPassword)) and ((lbledtusername.Text <>
- Teacher_Username[Current].TeacherUsername)
- or (lbledtPassword.Text <> Teacher_Password[Current].TeacherPassword))
- or (lbledtPassword.Text = '') or
- (lbledtUsername.Text = '')then
- begin
- Showmessage('Incorrect Login');
- end
- 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