Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.16 KB | None | 0 0
  1. nit 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.     procedure FormCreate(Sender: TObject);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. var
  25.   frmLogin: TfrmLogin;
  26.  
  27. implementation
  28. uses
  29.  Unit_AddLogin,UnitStudent_menu,Unit_TeacherMenu;  //Allows access to the form add login and studnet menu
  30. {$R *.dfm}
  31.  
  32. Type
  33. TPassword = record    //creating a record for the file to store passwords.
  34. Password : string[20];
  35. end;
  36.  
  37. Type
  38. TStudentNumber = record
  39. StudentNumber : String[6];
  40. end;
  41.  
  42. var
  43. PasswordFile : File of Tpassword;    // This will be the file whch stores the usernames
  44. StudentNumberFile : File of TStudentNumber;
  45. New_Password : array [1..1000] of TPassword;       //An array used to store multiple Passwords
  46. New_StudentNumber : array [1..1000] of TStudentNumber;
  47. Path : String;
  48.  
  49. procedure TfrmLogin.btnEnterClick(Sender: TObject);
  50. var
  51. count,counter,I,Temp_num : integer;
  52. Correct : Boolean;
  53. CurrentFile : TextFile;
  54. begin
  55.   {Code to check if teacher is trying to login in to the system}
  56.   if (lbledtusername.Text = 'David.Searle') and (lbledtPassword.Text = 'Tudor') then  //This is the hardcoded login detials for Mr Searl's account
  57.       begin
  58.       frmTeacherMenu.Show;      //Shows the form where the teacher can create new users
  59.       end;
  60.  
  61.    AssignFile(PasswordFile ,Path +'Password.dat');   //assigns exsiting file to Passwordfile
  62.    reset(PasswordFile );             //opens the file
  63.    AssignFile(StudentNumberFile ,Path +'StudentNumber.dat');   //assigns exsiting file to StudentNumberFile
  64.    reset(StudentNumberFile );
  65.    count := 0;    //intialises count
  66.  
  67.    while not  eof (StudentNumberFile) and not Eof (passwordfile) do
  68.    {This will repeat the code below untill the end of file is reached}
  69.     begin
  70.       count := count + 1;
  71.       Read(Passwordfile,New_Password[count]);  //reads the password from Passwordfile
  72.       Read(StudentNumberFile,New_StudentNumber[count]);
  73.  
  74.       if ((lbledtusername.Text = New_StudentNumber[count].StudentNumber)  and
  75.       (lbledtPassword.Text = New_Password[count].Password)) then
  76.        begin
  77.         frmStudentmenu.Show;   //if the login credentials is correct it shows the student menu
  78.        end;
  79.     end;
  80.     CloseFile(Passwordfile);  //Closes file which contains passwords
  81.     CloseFile(StudentNumberFile);
  82.    {Code to output incorrect login}
  83.     I := 0;
  84.    for counter  := 1 to count do
  85.     begin
  86.       I := I + 1;
  87.       if (lbledtusername.Text = New_StudentNumber[I].StudentNumber) and
  88.        (lbledtPassword.Text = New_Password[I].Password)  then
  89.        begin
  90.         Temp_num:= I;
  91.        end;
  92.       end;
  93.  
  94.       Correct := True;
  95.       if ((lbledtusername.Text <> New_StudentNumber[temp_num].StudentNumber)) then
  96.           begin
  97.             Correct := False;
  98.           end;
  99.  
  100.    //This checks that the user enters either teacher or student login
  101.   if  ((Correct = False)  and
  102.       (lbledtPassword.Text <> New_Password[temp_num].Password)) and ((lbledtusername.Text <>
  103.        'David.Searle')or (lbledtPassword.Text <> 'Tudor')) or (lbledtPassword.Text = '') or
  104.        (lbledtUsername.Text = '')then
  105.          begin
  106.           Showmessage('Incorrect Login');
  107.          end;
  108.  
  109.    AssignFile(CurrentFile,'CurrentUser.txt');    //assigns exsiting file to New_usernamefile
  110.    ReWrite(CurrentFile);                       //opens the file
  111.    Writeln(CurrentFile,New_StudentNumber[Temp_num].StudentNumber);
  112.    Writeln(CurrentFile,New_Password[Temp_num].Password);
  113.    CloseFile(CurrentFile);
  114.  
  115.  
  116.  
  117.  
  118.  
  119. end;
  120.  
  121.  
  122.  
  123. procedure TfrmLogin.ExitClick(Sender: TObject);
  124. begin
  125.   close;
  126. end;
  127.  
  128. procedure TfrmLogin.FormCreate(Sender: TObject);
  129. var
  130. count : integer;
  131. begin
  132.   Count := Count + 1;
  133.   if Count = 1 then
  134.    begin
  135.     Path := GetCurrentDir;
  136.     Count := 2;
  137.    end;
  138.  
  139. end;
  140.  
  141. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement