Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.65 KB | None | 0 0
  1. unit UnitLogin;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  7.   System.Classes, Vcl.Graphics,
  8.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Main, GeneralTopic,
  9.   UnitNewUser;
  10.  
  11. type
  12.   TfrmLogin = class(TForm)
  13.     btnLogin: TButton; // btn prefix = button
  14.     lbledtUsername: TLabeledEdit;
  15.     // lbledt = label that data can be inputted into while program is running
  16.     lbledtPassword: TLabeledEdit;
  17.     btnAdd_New_User: TButton;
  18.     lblLoginSuccessful: TLabel; // lbl prefix = label containing data
  19.     btnContinue: TButton;
  20.     lblMessage: TLabel;
  21.     btnLogout: TButton;
  22.     Shortcut: TButton;
  23.     procedure btnLoginClick(Sender: TObject);
  24.     procedure FormCreate(Sender: TObject);
  25.     procedure btnAdd_New_UserClick(Sender: TObject);
  26.     procedure btnContinueClick(Sender: TObject);
  27.     procedure btnLogoutClick(Sender: TObject);
  28.     procedure ShortcutClick(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.   public
  32.     { Public declarations }
  33.     Username, Password: string;
  34.     Userfile: textfile;
  35.     TextString: string;
  36.   end;
  37.  
  38. var
  39.   frmLogin: TfrmLogin;
  40.  
  41. implementation
  42.  
  43. {$R *.dfm}
  44.  
  45. procedure TfrmLogin.FormCreate(Sender: TObject);
  46. begin
  47.   lblMessage.show;
  48.   lbledtUsername.show;
  49.   lbledtPassword.show;
  50.   btnAdd_New_User.show;
  51.   btnLogin.show;
  52.  
  53.   lblLoginSuccessful.hide;
  54.   btnContinue.hide;
  55.   btnLogout.hide;
  56. end;
  57.  
  58. procedure TfrmLogin.ShortcutClick(Sender: TObject);
  59. begin
  60.   GeneralTopics.Show;
  61. end;
  62.  
  63. procedure TfrmLogin.btnAdd_New_UserClick(Sender: TObject);
  64. begin
  65.   FormNewUser.show; // show new user form
  66. end;
  67.  
  68. procedure TfrmLogin.btnContinueClick(Sender: TObject);
  69. begin
  70.   FormMainMenu.show; // show quiz menu
  71. end;
  72.  
  73. procedure TfrmLogin.btnLoginClick(Sender: TObject);
  74. Var
  75.   closing, found, Endendof, incpass: boolean;
  76. begin
  77.   closing := false;
  78.   found := false;
  79.   Endendof := false;
  80.   incpass := false;
  81.   Username := lbledtUsername.Text;
  82.   Password := lbledtPassword.Text;
  83.  
  84.   AssignFile(Userfile, 'Usernames.txt'); // open and read Usernames file
  85.   Reset(Userfile);
  86.   while (closing = false) do
  87.   begin
  88.     readln(Userfile, TextString); // read file line by line
  89.     if (TextString = Username) then
  90.     // compare username stored in file to value entered in the username box
  91.     begin
  92.  
  93.       readln(Userfile, TextString);
  94.       if (TextString = Password) then
  95.       // compare password under that username stored in file to value entered in the password box
  96.       begin
  97.         lbledtUsername.hide; // Hide Username Box
  98.         lbledtPassword.hide; // Hide Password Box
  99.         lblMessage.hide;
  100.         btnLogout.show;
  101.         btnAdd_New_User.hide; // Hide the Button to add new user
  102.         btnLogin.hide; // Hide Button the check login details
  103.         btnContinue.show;
  104.         lblLoginSuccessful.show;
  105.         closing := true;
  106.         found := true;
  107.       end
  108.       else
  109.       begin
  110.         closing := true;
  111.         Showmessage('Please enter your Log In details correctly');
  112.         // Displaying error message
  113.         incpass := true;
  114.       end;
  115.  
  116.     end;
  117.  
  118.   end;
  119.  
  120.   if (found = false) then
  121.   begin
  122.     closing := true;
  123.  
  124.     if (incpass = false) then
  125.     begin
  126.       Showmessage('Incorrect Username');
  127.     end;
  128.     found := true;
  129.   end;
  130.  
  131.   closefile(Userfile);
  132. end;
  133.  
  134. procedure TfrmLogin.btnLogoutClick(Sender: TObject);
  135. // returns to orignal login layout
  136. begin
  137.   lbledtUsername.show;
  138.   lbledtPassword.show;
  139.   btnAdd_New_User.show;
  140.   btnLogin.show;
  141.   lblLoginSuccessful.hide;
  142.   btnContinue.hide;
  143.   btnLogout.hide;
  144.   lblMessage.show;
  145.   lbledtUsername.Text := '';
  146.   lbledtPassword.Text := '';
  147. end;
  148.  
  149. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement