Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit UnitLogin;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
- System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Main, GeneralTopic,
- UnitNewUser;
- type
- TfrmLogin = class(TForm)
- btnLogin: TButton; // btn prefix = button
- lbledtUsername: TLabeledEdit;
- // lbledt = label that data can be inputted into while program is running
- lbledtPassword: TLabeledEdit;
- btnAdd_New_User: TButton;
- lblLoginSuccessful: TLabel; // lbl prefix = label containing data
- btnContinue: TButton;
- lblMessage: TLabel;
- btnLogout: TButton;
- Shortcut: TButton;
- procedure btnLoginClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure btnAdd_New_UserClick(Sender: TObject);
- procedure btnContinueClick(Sender: TObject);
- procedure btnLogoutClick(Sender: TObject);
- procedure ShortcutClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- Username, Password: string;
- Userfile: textfile;
- TextString: string;
- end;
- var
- frmLogin: TfrmLogin;
- implementation
- {$R *.dfm}
- procedure TfrmLogin.FormCreate(Sender: TObject);
- begin
- lblMessage.show;
- lbledtUsername.show;
- lbledtPassword.show;
- btnAdd_New_User.show;
- btnLogin.show;
- lblLoginSuccessful.hide;
- btnContinue.hide;
- btnLogout.hide;
- end;
- procedure TfrmLogin.ShortcutClick(Sender: TObject);
- begin
- GeneralTopics.Show;
- end;
- procedure TfrmLogin.btnAdd_New_UserClick(Sender: TObject);
- begin
- FormNewUser.show; // show new user form
- end;
- procedure TfrmLogin.btnContinueClick(Sender: TObject);
- begin
- FormMainMenu.show; // show quiz menu
- end;
- procedure TfrmLogin.btnLoginClick(Sender: TObject);
- Var
- closing, found, Endendof, incpass: boolean;
- begin
- closing := false;
- found := false;
- Endendof := false;
- incpass := false;
- Username := lbledtUsername.Text;
- Password := lbledtPassword.Text;
- AssignFile(Userfile, 'Usernames.txt'); // open and read Usernames file
- Reset(Userfile);
- while (closing = false) do
- begin
- readln(Userfile, TextString); // read file line by line
- if (TextString = Username) then
- // compare username stored in file to value entered in the username box
- begin
- readln(Userfile, TextString);
- if (TextString = Password) then
- // compare password under that username stored in file to value entered in the password box
- begin
- lbledtUsername.hide; // Hide Username Box
- lbledtPassword.hide; // Hide Password Box
- lblMessage.hide;
- btnLogout.show;
- btnAdd_New_User.hide; // Hide the Button to add new user
- btnLogin.hide; // Hide Button the check login details
- btnContinue.show;
- lblLoginSuccessful.show;
- closing := true;
- found := true;
- end
- else
- begin
- closing := true;
- Showmessage('Please enter your Log In details correctly');
- // Displaying error message
- incpass := true;
- end;
- end;
- end;
- if (found = false) then
- begin
- closing := true;
- if (incpass = false) then
- begin
- Showmessage('Incorrect Username');
- end;
- found := true;
- end;
- closefile(Userfile);
- end;
- procedure TfrmLogin.btnLogoutClick(Sender: TObject);
- // returns to orignal login layout
- begin
- lbledtUsername.show;
- lbledtPassword.show;
- btnAdd_New_User.show;
- btnLogin.show;
- lblLoginSuccessful.hide;
- btnContinue.hide;
- btnLogout.hide;
- lblMessage.show;
- lbledtUsername.Text := '';
- lbledtPassword.Text := '';
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement