daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Mar 20th, 2017 145 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unit Unit_AddLogin;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  7.   Vcl.StdCtrls, Vcl.Controls, Vcl.ExtCtrls, Vcl.Graphics,
  8. Vcl.Forms, Vcl.Dialogs;
  9.  
  10. type
  11.   TfrmAddlogin = class(TForm)
  12.     lbledtNew_username: TLabeledEdit;
  13.     lbledtNew_Password: TLabeledEdit;
  14.     btnSubmit: TButton;
  15.     btnExit: TButton;
  16.     procedure btnSubmitClick(Sender: TObject);
  17.     //procedure btnShowClick(Sender: TObject);
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure btnExitClick(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. var
  27.   frmAddlogin: TfrmAddlogin;
  28.  
  29. implementation
  30. uses
  31. Unit_Login,Unit_TeacherMenu; //Allows this form to use the login unit
  32. {$R *.dfm}
  33.  
  34.  
  35. type
  36. TUsername = record
  37. Username :string[20];
  38. end;
  39. type
  40. TPassword = record
  41. Password:string[20];
  42. end;
  43.  
  44. Var
  45. UsernameFile : File of TUsername;  //File which will store usernames
  46. PasswordFile : File of TPassword;  //FIle which will store Password
  47. New_username : array [1..1000] of Tusername;
  48. New_Password : array [1..1000] of TPassword;
  49. count,counter,number : integer; //Variables used when reading from file and writting to array
  50.  
  51.  
  52. procedure TfrmAddlogin.btnExitClick(Sender: TObject);
  53. begin
  54.   Close;
  55. end;
  56.  
  57. procedure TfrmAddlogin.btnSubmitClick(Sender: TObject);
  58. var
  59. I: integer;
  60. begin
  61.  // To check username file
  62.    AssignFile(Usernamefile,'loginsave.dat');
  63.    reset(UsernameFile);
  64.    count := 0;
  65.    while not Eof(Usernamefile) do
  66.     begin
  67.       count := count + 1;
  68.       Read(Usernamefile,New_username[Count]);     //reads all the usernames that first stored in the file
  69.     end;
  70.     Closefile(Usernamefile);
  71.  
  72.   //To create usernames
  73.   AssignFile(Usernamefile,'loginsave.dat');
  74.   reset(Usernamefile);
  75.   count := count + 1; //increments the pointer to store in the array without overwriting any data
  76.  
  77.  
  78.   New_Username[count].Username := lbledtNew_Username.text;
  79.   i := 0;
  80.   //The following code is a presence check. This ensure that the password field is not left blank
  81.    if (New_Username[count].Username = lbledtNew_Username.text) and (lbledtNew_Password.text = '') then
  82.    {If any of the fields are blanl then the user will be notifed and the form will close}
  83.    begin
  84.     Showmessage('Error enter a Password');
  85.     close;
  86.     FrmteacherMenu.Show;
  87.    end;
  88.   if (lbledtNew_Username.text <> '') and (lbledtNew_Password.text <> '') then {the code will not run
  89.   if the any of the fields are blank}
  90.   begin
  91.   for number := 1 to count do
  92.   begin
  93.     I := I + 1;
  94.     Write(UsernameFile,New_username[I]);    //stores the usernames into the array
  95.  
  96.  
  97.   end;
  98.  
  99.   CloseFile(Usernamefile);
  100.   end;
  101.  
  102.   // to check password file
  103.  AssignFile(Passwordfile,'Password.dat');
  104.    reset(PasswordFile);
  105.    count := 0;
  106.    while not Eof(Passwordfile) do
  107.     begin
  108.       count := count + 1;
  109.       Read(Passwordfile,New_Password[Count]);     //reads all the usernames that first stored in the file
  110.     end;
  111.     Closefile(Passwordfile);
  112.  
  113.   //TO cretae Passwords
  114.   AssignFile(Passwordfile,'Password.dat');
  115.   reset(Passwordfile);
  116.   count := count + 1; //increments the pointer to store in the array without overwriting any data
  117.   New_Password[count].Password := lbledtNew_Password.text;
  118.   //The following code is a presence check. This ensure that the Username field is not left blank
  119.   if (lbledtNew_Username.text = '') and (New_Password[count].Password = lbledtNew_Password.text) then
  120.    begin
  121.     Showmessage('Error enter a Username');
  122.     close;
  123.     FrmteacherMenu.Show;
  124.    end;
  125.   if (lbledtNew_Username.text <> '') and (lbledtNew_Password.text <> '') then
  126.   begin
  127.     count := count + 1; //increments the pointer to store in the array without overwriting any data
  128.     New_Password[count].Password := lbledtNew_Password.text;
  129.     i := 0;
  130.     for number := 1 to count do
  131.     begin
  132.     I := I + 1;
  133.     Write(PasswordFile,New_Password[I]);    //stores the Password into the array
  134.     end;
  135.   end;
  136.  
  137.   CloseFile(Passwordfile);
  138.  
  139. end;
  140.  
  141.  
  142. procedure TfrmAddlogin.FormCreate(Sender: TObject);
  143. begin
  144.   lbledtNew_Password.text := '';
  145.   lbledtNew_Username.Text := '';
  146. end;
  147.  
  148. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top