Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.00 KB | None | 0 0
  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.     //The following code is a presence check. This ensure that the Username field is not left blank
  117.   if (lbledtNew_Username.text = '') and (New_Password[count].Password = lbledtNew_Password.text) then
  118.    begin
  119.     Showmessage('Error enter a Username');
  120.     close;
  121.     FrmteacherMenu.Show;
  122.    end;
  123.   if (lbledtNew_Username.text <> '') and (lbledtNew_Password.text <> '') then
  124.   begin
  125.     count := count + 1; //increments the pointer to store in the array without overwriting any data
  126.     New_Password[count].Password := lbledtNew_Password.text;
  127.     i := 0;
  128.     for number := 1 to count do
  129.     begin
  130.     I := I + 1;
  131.     Write(PasswordFile,New_Password[I]);    //stores the Password into the array
  132.     end;
  133.   end;
  134.  
  135.   CloseFile(Passwordfile);
  136.  
  137. end;
  138.  
  139.  
  140. procedure TfrmAddlogin.FormCreate(Sender: TObject);
  141. begin
  142.   lbledtNew_Password.text := '';
  143.   lbledtNew_Username.Text := '';
  144. end;
  145.  
  146. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement