Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.49 KB | None | 0 0
  1. unit Unit_Login;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
  8.  
  9. type
  10.   TfrmLogin = class(TForm)
  11.     lbledtUsername: TLabeledEdit;
  12.     lbledtPassword: TLabeledEdit;
  13.     btnEnter: TButton;
  14.     Exit: TButton;
  15.     procedure btnEnterClick(Sender: TObject);
  16.     procedure ExitClick(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   frmLogin: TfrmLogin;
  25.  
  26. implementation
  27. uses
  28.  Unit_AddLogin,UnitStudent_menu,Unit_TeacherMenu;  //Allows access to the form add login and studnet menu
  29. {$R *.dfm}
  30. type
  31. TUsername = record //creating a record for the file to store usernames
  32. Username : string[20];
  33. end;
  34.  
  35. type
  36. TPassword = record    //creating a record for the file to store passwords.
  37. Password:string[20];
  38. end;
  39.  
  40. var
  41. UsernameFile : File of TUsername;
  42. PasswordFile : File of Tpassword;    // This will be the file whch stores the usernames
  43. New_username : array  [1..1000] of Tusername;    //An array used to store multiple usernames
  44. New_Password : array [1..1000] of TPassword;       //An array used to store multiple Passwords
  45.  
  46. procedure TfrmLogin.btnEnterClick(Sender: TObject);
  47. var
  48. count,counter,I,Temp_num : integer;
  49. begin
  50.   {Code to check if teacher is trying to login in to the system}
  51.   if (lbledtusername.Text = 'David.Searle') and (lbledtPassword.Text = 'Tudor') then  //This is the hardcoded login detials for Mr Searl's account
  52.       begin
  53.       frmTeacherMenu.Show;      //Shows the form where the teacher can create new users
  54.       end;
  55.  
  56.   {Code to check if a student is logging in to the system}
  57.    AssignFile(Usernamefile,'loginsave.dat');    //assigns exsiting file to New_usernamefile
  58.    reset(UsernameFile);                       //opens the file
  59.  
  60.    AssignFile(PasswordFile ,'Password.dat');   //assigns exsiting file to New_Passwordfile
  61.    reset(PasswordFile );             //opens the file
  62.  
  63.    count := 0;    //intialises count
  64.  
  65.    while not Eof(Usernamefile) and not Eof (passwordfile) do {This will repeat the code below untill
  66.     the end of file is reached}
  67.     begin
  68.       count := count + 1;
  69.       Read(Usernamefile,New_username[count]);   //reads the usernames from Usernamefile
  70.       Read(Passwordfile,New_Password[count]);  //reads the password from Passwordfile
  71.       if (lbledtusername.Text = New_username[count].Username) and
  72.       (lbledtPassword.Text = New_Password[count].Password) then
  73.        begin
  74.         frmStudentmenu.Show;   //if the username is correct it shows the student menu
  75.        end;
  76.     end;
  77.     Closefile(Usernamefile);  //closes file which contains username
  78.     Closefile(Passwordfile);  //Closes file which contains passwords
  79.  
  80.  
  81.    {Code to output incorrect login}
  82.     I := 0;
  83.    for counter  := 1 to count do
  84.     begin
  85.       I := I + 1;
  86.       if (lbledtusername.Text = New_username[I].Username) and
  87.        (lbledtPassword.Text = New_Password[I].Password)  then
  88.        begin
  89.         Temp_num:= I;
  90.        end;
  91.       end;
  92.    //This checks that the user enters either teacher or student login
  93.   if  ((lbledtusername.Text <> New_username[temp_num].Username) or
  94.        (lbledtPassword.Text <> New_Password[temp_num].Password)) and ((lbledtusername.Text <>
  95.        'David.Searle')or (lbledtPassword.Text <> 'Tudor'))   then
  96.         Showmessage('Incorrect Login');
  97.  
  98. end;
  99.  
  100.  
  101.  
  102. procedure TfrmLogin.ExitClick(Sender: TObject);
  103. begin
  104.   close;
  105. end;
  106.  
  107. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement