Advertisement
Guest User

Untitled

a guest
Mar 15th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.45 KB | None | 0 0
  1. unit MenuSignUp;
  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, strutils;
  9.  
  10. type
  11.   TUserInfo = Record
  12.     Username: String[25];
  13.     Password: String[25];
  14.   End;
  15.  
  16.   TFormSignUp = class(TForm)
  17.     Label1: TLabel;
  18.     Label2: TLabel;
  19.     Label3: TLabel;
  20.     Label4: TLabel;
  21.     btnSignUp: TButton;
  22.     edtUsername: TEdit;
  23.     edtPass: TEdit;
  24.     edtRePass: TEdit;
  25.     lblPassmatch: TLabel;
  26.     btnExit: TButton;
  27.     lblCaseError: TLabel;
  28.     procedure edtRePassKeyUp(Sender: TObject; var Key: Word;
  29.       Shift: TShiftState);
  30.     procedure edtPassKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  31.     procedure edtUsernameKeyUp(Sender: TObject; var Key: Word;
  32.       Shift: TShiftState);
  33.     procedure btnSignUpClick(Sender: TObject);
  34.     procedure btnExitClick(Sender: TObject);
  35.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  36.     procedure FormCreate(Sender: TObject);
  37.  
  38.   private
  39.     { Private declarations }
  40.   public
  41.  
  42.   end;
  43.  
  44. var
  45.   FormSignUp: TFormSignUp;
  46.   Username: String;
  47.   Password: String;
  48.   Info: File of TUserInfo;
  49.   UserInfo: TUserInfo;
  50.  
  51. implementation
  52.  
  53. {$R *.dfm}
  54.  
  55. uses MenuLoginSignUp;
  56.  
  57. function upcase(Password: string): Boolean;
  58. var
  59.   wordlength, count1, count2: integer;
  60.   C: string;
  61.   bool, cancel: Boolean;
  62. begin
  63.   wordlength := length(Password);
  64.   upcase := false;
  65.   cancel := false;
  66.   for count1 := 1 to wordlength do
  67.   begin
  68.     C := Password[count1];
  69.     for count2 := 0 to 9 do
  70.     begin
  71.       if C = inttostr(count2) then
  72.         cancel := true;
  73.     end;
  74.  
  75.     if (C = uppercase(C)) and (not cancel) then
  76.       bool := true;
  77.   end;
  78.   result := bool;
  79. end;
  80.  
  81. function lc(Password: string): Boolean;
  82. var
  83.   wordlength, count1, count2: integer;
  84.   C: string;
  85.   bool, cancel: Boolean;
  86.  
  87. begin
  88.   wordlength := length(Password);
  89.   lc := false;
  90.   cancel := false;
  91.   for count1 := 1 to wordlength do
  92.   begin
  93.     C := Password[count1];
  94.  
  95.     for count2 := 0 to 9 do
  96.     begin
  97.       if C = inttostr(count2) then
  98.         cancel := true;
  99.     end;
  100.     if (C = lowercase(C)) and (not cancel) then
  101.  
  102.       bool := true
  103.   end;
  104.   result := bool;
  105. end;
  106.  
  107. function NumCheck(Password: string): Boolean;
  108. var
  109.   wordlength, count1, count2: integer;
  110.   C: string;
  111.   bool: Boolean;
  112.  
  113. begin
  114.   wordlength := length(Password);
  115.   NumCheck := false;
  116.   for count1 := 1 to wordlength do
  117.   begin
  118.     C := Password[count1];
  119.     for count2 := 0 to 9 do
  120.     begin
  121.       if C = inttostr(count2) then
  122.         bool := true
  123.     end;
  124.   end;
  125.   result := bool;
  126. end;
  127.  
  128. procedure CheckForAllCompleteFields;
  129. begin
  130.  
  131.   if (FormSignUp.lblPassmatch.Caption = 'Passwords Match') and
  132.     (FormSignUp.edtUsername.Text <> '') and (FormSignUp.edtPass.Text <> '') and
  133.     (FormSignUp.edtRePass.Text <> '') and (upcase(FormSignUp.edtPass.Text))
  134.     = true and (lc(FormSignUp.edtPass.Text)) = true and
  135.     (NumCheck(FormSignUp.edtPass.Text)) = true then
  136.     FormSignUp.btnSignUp.Enabled := true
  137.   else
  138.     FormSignUp.btnSignUp.Enabled := false;
  139. end;
  140.  
  141. procedure TFormSignUp.btnExitClick(Sender: TObject);
  142. begin
  143.   FormLoginSignUp.Visible := true;
  144.   sleep(10); // prevents flash when changing forms
  145.   FormSignUp.Visible := false;
  146.  
  147. end;
  148.  
  149. procedure TFormSignUp.btnSignUpClick(Sender: TObject);
  150. begin
  151.   Username := edtUsername.Text;
  152.   Password := edtPass.Text;
  153.   UserInfo.Username := edtUsername.Text;
  154.   UserInfo.Password := edtPass.Text;
  155.   FormLoginSignUp.Visible := true;
  156.   FormSignUp.Visible := false;
  157.  
  158. {$I-}
  159.   AssignFile(Info, 'UserInfo.dat');
  160.   Reset(Info);
  161.   // CloseFile(Info);
  162. {$I+}
  163.   if (IOResult <> 0) then
  164.   begin
  165.     Rewrite(Info);
  166.     closeFile(Info); // Create a new file to write to
  167.   end;
  168.  
  169.   AssignFile(Info, 'UserInfo.dat');
  170.   Reset(Info);
  171.   Seek(Info, Filesize(Info)); // find EoF
  172.   Write(Info, UserInfo);
  173.   closeFile(Info);
  174.  
  175. end;
  176.  
  177. procedure TFormSignUp.edtPassKeyUp(Sender: TObject; var Key: Word;
  178.   Shift: TShiftState);
  179.  
  180. var
  181.   ContainsUpper, ContainsLower, ContainsNum: Boolean;
  182. begin
  183.  
  184.   lblPassmatch.Visible := true;
  185.   if (edtPass.Text <> edtRePass.Text) then
  186.     lblPassmatch.Caption := 'Passwords do not match';
  187.   if edtPass.Text <> edtRePass.Text then
  188.     lblPassmatch.Font.Color := clRed
  189.   else
  190.   begin
  191.     lblPassmatch.Caption := 'Passwords Match';
  192.     lblPassmatch.Font.Color := clGreen;
  193.   end;
  194.  
  195.   ContainsUpper := upcase(FormSignUp.edtPass.Text);
  196.   ContainsLower := lc(FormSignUp.edtPass.Text);
  197.   ContainsNum := NumCheck(FormSignUp.edtPass.Text);
  198.  
  199.   if not(ContainsUpper) or not(ContainsLower) or not(ContainsNum) then
  200.   begin
  201.     if not(ContainsUpper) then
  202.       FormSignUp.lblCaseError.Caption :=
  203.         'Your password must contain an upper case letter'
  204.     else if not(ContainsLower) then
  205.       FormSignUp.lblCaseError.Caption :=
  206.         'Your password must contain a lower case letter'
  207.     else if not(ContainsNum) then
  208.       FormSignUp.lblCaseError.Caption := 'Your password must contain a Number'
  209.  
  210.   end
  211.   else
  212.     FormSignUp.lblCaseError.Caption := '';
  213.  
  214.   CheckForAllCompleteFields;
  215. end;
  216.  
  217. procedure TFormSignUp.edtRePassKeyUp(Sender: TObject; var Key: Word;
  218.   Shift: TShiftState);
  219. begin
  220.   lblPassmatch.Visible := true;
  221.   if edtPass.Text <> edtRePass.Text then
  222.     lblPassmatch.Caption := 'Passwords do not match';
  223.  
  224.   if edtPass.Text <> edtRePass.Text then
  225.     lblPassmatch.Font.Color := clRed
  226.  
  227.   else
  228.   begin
  229.     lblPassmatch.Caption := 'Passwords Match';
  230.     lblPassmatch.Font.Color := clGreen;
  231.   end;
  232.   CheckForAllCompleteFields;
  233. end;
  234.  
  235. procedure TFormSignUp.edtUsernameKeyUp(Sender: TObject; var Key: Word;
  236.   Shift: TShiftState);
  237. Var
  238.   UserTaken: Boolean;
  239. begin
  240.   UserTaken := true;
  241.  
  242.   AssignFile(Info, 'userinfo.dat');
  243.   Reset(Info);
  244.   while Not EoF(Info) do
  245.   begin
  246.     Read(Info, UserInfo);
  247.     if edtUsername.Text = UserInfo.Username then
  248.       btnSignUp.Enabled := false
  249.       // Implement label change
  250.     else // for this...............
  251.       UserTaken := false;
  252.  
  253.     CheckForAllCompleteFields;
  254.   end;
  255.   closeFile(Info)
  256.  
  257. end;
  258.  
  259. procedure TFormSignUp.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  260. begin
  261.   FormSignUp.Visible := false;
  262.   FormLoginSignUp.Visible := true;
  263. end;
  264.  
  265. procedure TFormSignUp.FormCreate(Sender: TObject);
  266. begin
  267.   FormStyle := fsStayOnTop;
  268.   BorderStyle := bsNone;
  269.   Left := 0;
  270.   Top := 0;
  271.   Width := Screen.Width;
  272.   Height := Screen.Height;
  273.  
  274. end;
  275.  
  276. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement