Community discussion forum

Help with line reading from txt file

  • 2 years ago

    Hi,

    Was reading this tutorial : http://www.developerfusion.co.uk/show/37/5/ and I wondered if there was a way to read every OTHER line, rather than every line.

    I'm making a small login program where you can register.. but i need to read usernames from a txt file and see if it has been taken. 

    At the moment the format in my txt file is:

    username
    password
    username
    password


    Regards

    Loader

  • 2 years ago

    1.) I assume that you use some code like this at the moment:

    ...
    Do While Not EOF(nFileNum)
        Line Input #nFileNum, sNextLine
        'do something with it
        'add line numbers to it, in this case!
        sNextLine = lLineCount & " " & sNextLine & vbCrLf
        sText = sText & sNextLine
        lLineCount = lLineCount + 1
    Loop
    ...

    Please try to modify this code to something like this:

    dim username(999) as string
    dim password(999) as string
    dim counter as integer
    ...
    Do While Not EOF(nFileNum)
        Line Input #nFileNum, username(counter)
        Line Input #nFileNum, password(counter)
        lLineCount = lLineCount + 2
        counter = counter + 1
    Loop
    ...

    2.) The security of your application is the worst I have ever seen. Storing usernames and passwords as plain text is like using no usernames and no passwords. If some people are using the same password for your application and other applications, you are also compromising these applications and not only your own. Please try to use at least some basic methods of encryption to usernames, passwords and the file name.
  • 2 years ago
    use an basic encryption to strore the username and passwords....

    and never use the extension as .txt use something else or do not use it at all...this will make the attacker job a bit hader( remember just a bit may be)

    I am also trying to create a program ...please standby





  • 2 years ago

    Heres a basic encryption function which you could use to at least make it slightly harder to discover your passwords:

    Private Function Encrypt(ByVal RawString As String)
        Dim x, i, tmp
        For i = 1 To Len(RawString)
            x = Mid(RawString, i, 1)
            tmp = tmp & Chr(Asc(x) + 1)
        Next
        tmp = StrReverse(tmp)
        Encrypt = tmp
    End Function

    To encrypt a string just call it like:
    Dim myString As String
    myString = Encrypt(Text1.Text)

    Use logic like that provided by Zorro_ot to encrypt your passwords:

    Open "C:\inputfile.txt" For Input As #1
    Open "C:\encryptedfile.txt" For Output As #2
    Do While Not EOF(1)
        Dim inString, outString As String
        Line Input #1, inString
        Print #2, inString
        Line Input #1, inString
        outString = Encrypt(inString)
        Print #2, outString
    Loop
    Close #1
    Close #2

    Now, when you wish to compare a password, encrypt the raw string and compare the two encrypted strings.  There are far more effective methods of encryption such as MD5 hashing but this is better than nothing!!!






























Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback