Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit MenuSignUp;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
- System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, strutils;
- type
- TUserInfo = Record
- Username: String[25];
- Password: String[25];
- End;
- TFormSignUp = class(TForm)
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- btnSignUp: TButton;
- edtUsername: TEdit;
- edtPass: TEdit;
- edtRePass: TEdit;
- lblPassmatch: TLabel;
- btnExit: TButton;
- lblCaseError: TLabel;
- procedure edtRePassKeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure edtPassKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure edtUsernameKeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure btnSignUpClick(Sender: TObject);
- procedure btnExitClick(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- end;
- var
- FormSignUp: TFormSignUp;
- Username: String;
- Password: String;
- Info: File of TUserInfo;
- UserInfo: TUserInfo;
- implementation
- {$R *.dfm}
- uses MenuLoginSignUp;
- function upcase(Password: string): Boolean;
- var
- wordlength, count1, count2: integer;
- C: string;
- bool, cancel: Boolean;
- begin
- wordlength := length(Password);
- upcase := false;
- cancel := false;
- for count1 := 1 to wordlength do
- begin
- C := Password[count1];
- for count2 := 0 to 9 do
- begin
- if C = inttostr(count2) then
- cancel := true;
- end;
- if (C = uppercase(C)) and (not cancel) then
- bool := true;
- end;
- result := bool;
- end;
- function lc(Password: string): Boolean;
- var
- wordlength, count1, count2: integer;
- C: string;
- bool, cancel: Boolean;
- begin
- wordlength := length(Password);
- lc := false;
- cancel := false;
- for count1 := 1 to wordlength do
- begin
- C := Password[count1];
- for count2 := 0 to 9 do
- begin
- if C = inttostr(count2) then
- cancel := true;
- end;
- if (C = lowercase(C)) and (not cancel) then
- bool := true
- end;
- result := bool;
- end;
- function NumCheck(Password: string): Boolean;
- var
- wordlength, count1, count2: integer;
- C: string;
- bool: Boolean;
- begin
- wordlength := length(Password);
- NumCheck := false;
- for count1 := 1 to wordlength do
- begin
- C := Password[count1];
- for count2 := 0 to 9 do
- begin
- if C = inttostr(count2) then
- bool := true
- end;
- end;
- result := bool;
- end;
- procedure CheckForAllCompleteFields;
- begin
- if (FormSignUp.lblPassmatch.Caption = 'Passwords Match') and
- (FormSignUp.edtUsername.Text <> '') and (FormSignUp.edtPass.Text <> '') and
- (FormSignUp.edtRePass.Text <> '') and (upcase(FormSignUp.edtPass.Text))
- = true and (lc(FormSignUp.edtPass.Text)) = true and
- (NumCheck(FormSignUp.edtPass.Text)) = true then
- FormSignUp.btnSignUp.Enabled := true
- else
- FormSignUp.btnSignUp.Enabled := false;
- end;
- procedure TFormSignUp.btnExitClick(Sender: TObject);
- begin
- FormLoginSignUp.Visible := true;
- sleep(10); // prevents flash when changing forms
- FormSignUp.Visible := false;
- end;
- procedure TFormSignUp.btnSignUpClick(Sender: TObject);
- begin
- Username := edtUsername.Text;
- Password := edtPass.Text;
- UserInfo.Username := edtUsername.Text;
- UserInfo.Password := edtPass.Text;
- FormLoginSignUp.Visible := true;
- FormSignUp.Visible := false;
- {$I-}
- AssignFile(Info, 'UserInfo.dat');
- Reset(Info);
- // CloseFile(Info);
- {$I+}
- if (IOResult <> 0) then
- begin
- Rewrite(Info);
- closeFile(Info); // Create a new file to write to
- end;
- AssignFile(Info, 'UserInfo.dat');
- Reset(Info);
- Seek(Info, Filesize(Info)); // find EoF
- Write(Info, UserInfo);
- closeFile(Info);
- end;
- procedure TFormSignUp.edtPassKeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- var
- ContainsUpper, ContainsLower, ContainsNum: Boolean;
- begin
- lblPassmatch.Visible := true;
- if (edtPass.Text <> edtRePass.Text) then
- lblPassmatch.Caption := 'Passwords do not match';
- if edtPass.Text <> edtRePass.Text then
- lblPassmatch.Font.Color := clRed
- else
- begin
- lblPassmatch.Caption := 'Passwords Match';
- lblPassmatch.Font.Color := clGreen;
- end;
- ContainsUpper := upcase(FormSignUp.edtPass.Text);
- ContainsLower := lc(FormSignUp.edtPass.Text);
- ContainsNum := NumCheck(FormSignUp.edtPass.Text);
- if not(ContainsUpper) or not(ContainsLower) or not(ContainsNum) then
- begin
- if not(ContainsUpper) then
- FormSignUp.lblCaseError.Caption :=
- 'Your password must contain an upper case letter'
- else if not(ContainsLower) then
- FormSignUp.lblCaseError.Caption :=
- 'Your password must contain a lower case letter'
- else if not(ContainsNum) then
- FormSignUp.lblCaseError.Caption := 'Your password must contain a Number'
- end
- else
- FormSignUp.lblCaseError.Caption := '';
- CheckForAllCompleteFields;
- end;
- procedure TFormSignUp.edtRePassKeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- lblPassmatch.Visible := true;
- if edtPass.Text <> edtRePass.Text then
- lblPassmatch.Caption := 'Passwords do not match';
- if edtPass.Text <> edtRePass.Text then
- lblPassmatch.Font.Color := clRed
- else
- begin
- lblPassmatch.Caption := 'Passwords Match';
- lblPassmatch.Font.Color := clGreen;
- end;
- CheckForAllCompleteFields;
- end;
- procedure TFormSignUp.edtUsernameKeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- Var
- UserTaken: Boolean;
- begin
- UserTaken := true;
- AssignFile(Info, 'userinfo.dat');
- Reset(Info);
- while Not EoF(Info) do
- begin
- Read(Info, UserInfo);
- if edtUsername.Text = UserInfo.Username then
- btnSignUp.Enabled := false
- // Implement label change
- else // for this...............
- UserTaken := false;
- CheckForAllCompleteFields;
- end;
- closeFile(Info)
- end;
- procedure TFormSignUp.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- FormSignUp.Visible := false;
- FormLoginSignUp.Visible := true;
- end;
- procedure TFormSignUp.FormCreate(Sender: TObject);
- begin
- FormStyle := fsStayOnTop;
- BorderStyle := bsNone;
- Left := 0;
- Top := 0;
- Width := Screen.Width;
- Height := Screen.Height;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement