read/write username/password in txt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • carl2k2
    New Member
    • Mar 2008
    • 15

    read/write username/password in txt

    Ok trying to setup a simple user login system

    The first attempt I just used if statements for example

    Code:
    If txtusername = "carl" and txtpassword = "password" Then
    OK = True
    Form4.show
    else
    MSGbox("please enter correct details")
    end if
    Anyway the way above works, but I would like it if I can store the username/password in text file, so I can eventually setup self registration.

    I need a little push in the write direction for the code I need to start me off,
  • lotus18
    Contributor
    • Nov 2007
    • 865

    #2
    Follow this link.

    Rey Sean

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      Originally posted by carl2k2

      Anyway the way above works, but I would like it if I can store the username/password in text file, so I can eventually setup self registration.

      I need a little push in the write direction for the code I need to start me off,
      hi Carl

      Check the syntax of OPEN (for input, for output)

      e.g.
      [CODE=vb]
      Dim txtNumber as Integer
      txtnumber = freefile
      Open "C:\Passwords.t xt" For Input As #txtnumber[/CODE]

      Then you can use INPUT to store into a string and CLOSE, to do so.

      HTH

      Comment

      • carl2k2
        New Member
        • Mar 2008
        • 15

        #4
        Ok I used that tutorial although have a few errors since vista won't give me correct permissions(stu pid vista :@)

        This code needs modifying

        Code:
        Dim savefile As Long
        savefile = FreeFile()
        Open "F:\Users\Kate\Documents\savedfile.txt" For Output As #savefile
        Write #savefile, (Text1.Text), (Text2.Text)
        Close #savefile
        I need it so (text2.text) will be displayed under text 1,

        atm it displays as(in text file)

        "username1" , "password1"


        I need it so it will display as

        username1
        password1

        Comment

        • kadghar
          Recognized Expert Top Contributor
          • Apr 2007
          • 1302

          #5
          Originally posted by carl2k2
          atm it displays as(in text file)

          "username1" , "password1"


          I need it so it will display as

          username1
          password1
          Hate Vista too

          Use the SPLIT function to separate the string into an array
          to remove the " use REPLACE(yourStr ing, chr(34), "") before using the SPLIT, with comma as delimiter.

          Comment

          • carl2k2
            New Member
            • Mar 2008
            • 15

            #6
            Originally posted by kadghar
            Hate Vista too

            Use the SPLIT function to separate the string into an array
            to remove the " use REPLACE(yourStr ing, chr(34), "") before using the SPLIT, with comma as delimiter.
            Can you show me example in :

            Code:
            Dim savefile As Long
            savefile = FreeFile()
            Open "I:\College Work ------- Updated 2008 March\new-work\savedfile.txt" For Output As #savefile
            Write #savefile, (Text1.Text); Split(Text2.Text)
            Close #savefile
            I was reading, do i have to setup more variables for this :S?



            trying but getting errors,

            [PHP]Dim savefile As Long
            Dim test
            Dim test2
            Dim spilt
            spilt = Split((test), (test2))
            test = (Text1.Text)
            test2 = (Text2.Text)
            savefile = FreeFile()
            Open "I:\College Work ------- Updated 2008 March\new-work\savedfile. txt" For Output As #savefile
            Write #savefile, spilt
            Close #savefile[/PHP]

            im lost :/

            Comment

            • kadghar
              Recognized Expert Top Contributor
              • Apr 2007
              • 1302

              #7
              Originally posted by carl2k2
              Can you show me example in :

              Code:
              Dim savefile As Long
              savefile = FreeFile()
              Open "I:\College Work ------- Updated 2008 March\new-work\savedfile.txt" For Output As #savefile
              Write #savefile, (Text1.Text); Split(Text2.Text)
              Close #savefile
              I was reading, do i have to setup more variables for this :S?


              im lost :/
              ok, you're not that lost:

              [CODE=vb]Dim savefile As Long
              savefile = FreeFile()
              Open "I:\College Work ------- Updated 2008 March\new-work\savedfile. txt" For Output As #savefile[/CODE]

              So far, so good, now you have your file number 'savefile' where you wanted it.

              now, if i remember well, your first line was something like: "username","pas sword".

              now, lets create a couple of strings, and store the first line of your file there:
              [CODE=vb]dim Str1 as string
              dim Str2 as string
              input #savefile, str1 'reads "username"
              input #savefile,str2 'reads "password"
              [/CODE]

              now, all you have to do is compare str1 with user name, and str2 with password

              you can put this two last lines inside a

              While not eof(savefile) / wend

              HTH

              Comment

              Working...