Results 1 to 8 of 8

Thread: How can I pull my login information from an external file?

  1. #1
    Join Date
    Dec 2009
    Posts
    146
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default How can I pull my login information from an external file?

    I'd like to have my scripts go to an external file and pull my username, password, and pin number. What is the most efficient way to do that?

    I know I probably need to use ReadINI and WriteINI but I don't know how to do that.

    Thanks in advance,

    JIM

  2. #2
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Uhh.. shouldn't you know that info?

  3. #3
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    I wrote a function, dont know if it works, you should try it.
    SCAR Code:
    function ReadTheFile( PathToFile: String; I: Integer ): String;
    var S: String;
        F: Integer;
        TheArray: Array of String;
    begin
      F := OpenFile( PathToFile, False );
      ReadFileString( F, S, FileSize( F ) );
      CloseFile( F );
      TheArray := Explode( ';', S );
      Result := TheArray[ I ];
    end;

    Should read in the file like: username;password;pin

    For username I is 0, and for password it is 1, etc.
    There used to be something meaningful here.

  4. #4
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Easiest way would to be Savesetting/load setting as it's pretty fail proof, WriteCharsfile string is a kinda tricky... I'd recommend INI files as they are easy to manage and manipulate.

  5. #5
    Join Date
    Apr 2007
    Location
    Melbourne, Aus
    Posts
    202
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    jimthesoundman: you could make a scar script and save it in the include folder which has this in it:
    Code:
    procedure DeclarePlayers;
    begin
      HowManyPlayers := 1;                 //Total Number of Players.
      CurrentPlayer := 0;                  //Starting Player.
      NumberOfPlayers(HowManyPlayers);
    
      Players[0].Name :='username';        //Username.
      Players[0].Pass :='password';        //Password.
      Players[0].Nick :='ern';             //Nickname. (4 Letters of your username)
      Players[0].Active := True;           //Is the player active?
      Players[0].Pin := '1234';            //Leave blank if you dont have one.
    end;
    then put this in your script:
    Code:
    {.include LoginDetails.scar}

  6. #6
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    SCAR Code:
    program TheFile;

    function ReadTheFile( PathToFile: String; I: Integer ): String;
    var S: String;
        F: Integer;
        TheArray: Array of String;
    begin
      F := OpenFile( PathToFile, False );
      ReadFileString( F, S, FileSize( F ) );
      CloseFile( F );
      TheArray := Explode( ';', S );
      Result := TheArray[ I ];
    end;

    function WriteTheFile( PathToFile, NewString: String; I: Integer ): Boolean;
    var S, TheString: String;
        F, O: Integer;
        TheArray: Array of String;
    begin
      TheString := '';
      F := OpenFile( PathToFile, False );
      ReadFileString( F, S, FileSize( F ) );
      CloseFile( F );
      TheArray := Explode( ';', S );
      TheArray[ I ] := NewString;
      for O := 0 to GetArrayLength( TheArray ) - 1 do
      begin
        if not ( O = 0 ) then begin
          TheArray[ O ] := ';' + TheArray[ O ];
        end;
        TheString := TheString + TheArray[ O ];
      end;
      F := RewriteFile( PathToFile, False );
      WriteFileString( F, TheString );
      CloseFile( F );
      Result := True;
    end;

    begin
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 0 ) );
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 1 ) );
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 2 ) );
    WriteTheFile( ScriptPath + 'test.txt', 'usernametest', 0 );
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 0 ) );
    WriteTheFile( ScriptPath + 'test.txt', 'passwordtest', 1 );
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 1 ) );
    WriteTheFile( ScriptPath + 'test.txt', 'pintest', 2 );
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 2 ) );
    end.

    {OUTPUT:
    Successfully compiled (25 ms)
    username
    password
    pin
    usernametest
    passwordtest
    pintest
    Successfully executed
    FILE:
    username;password;pin
    }

    The function worked good but i still recommend to use ini files.

    E: Added a write function.
    Last edited by Frement; 02-01-2010 at 05:58 AM.
    There used to be something meaningful here.

  7. #7
    Join Date
    Dec 2009
    Posts
    146
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thank you all for your help. Very informative.

  8. #8
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    I'm still confused on why you need this..?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •