daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest Mar 20th, 2017 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.   //This is the hardcoded login detials for Mr Searl's account
  52.   if (lbledtusername.Text = 'David.Searle') and (lbledtPassword.Text = 'Tudor') then
  53.       begin
  54.       frmTeacherMenu.Show;      //Shows the form where the teacher can create new users
  55.       end;
  56.  
  57.   {Code to check if a student is logging in to the system}
  58.    AssignFile(Usernamefile,'loginsave.dat');    //assigns exsiting file to New_usernamefile
  59.    reset(UsernameFile);                       //opens the file
  60.  
  61.    AssignFile(PasswordFile ,'Password.dat');   //assigns exsiting file to New_Passwordfile
  62.    reset(PasswordFile );             //opens the file
  63.  
  64.    count := 0;    //intialises count
  65.  
  66.    while not Eof(Usernamefile) and not Eof (passwordfile) do {This will repeat the code below untill
  67.     the end of file is reached}
  68.     begin
  69.       count := count + 1;
  70.       Read(Usernamefile,New_username[count]);   //reads the usernames from Usernamefile
  71.       Read(Passwordfile,New_Password[count]);  //reads the password from Passwordfile
  72.       if (lbledtusername.Text = New_username[count].Username) and
  73.       (lbledtPassword.Text = New_Password[count].Password) then
  74.        begin
  75.         frmStudentmenu.Show;   //if the username is correct it shows the student menu
  76.        end;
  77.     end;
  78.     Closefile(Usernamefile);  //closes file which contains username
  79.     Closefile(Passwordfile);  //Closes file which contains passwords
  80.  
  81.  
  82.    {Code to output incorrect login}
  83.     I := 0;
  84.    for counter  := 1 to count do
  85.     begin
  86.       //The following code assess if the credntials enetred are in the username and password array
  87.       I := I + 1;
  88.       if (lbledtusername.Text = New_username[I].Username) and
  89.        (lbledtPassword.Text = New_Password[I].Password)  then
  90.        begin
  91.         Temp_num:= I;
  92.        end;
  93.       end;
  94.    //This checks that the user enters either teacher or student login
  95.   if  ((lbledtusername.Text <> New_username[temp_num].Username) or
  96.        (lbledtPassword.Text <> New_Password[temp_num].Password)) and ((lbledtusername.Text <>
  97.        'David.Searle')or (lbledtPassword.Text <> 'Tudor'))   then
  98.         Showmessage('Incorrect Login');
  99.  
  100. end;
  101.  
  102.  
  103.  
  104. procedure TfrmLogin.ExitClick(Sender: TObject);
  105. begin
  106.   close;
  107. end;
  108.  
  109. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top