I have an application that currently operates based on a static password that is hard coded into the application. I would like to somehow have the application look in a text file, say: C:\passtest.txt for a password. The text file will have nothing but the 1 password in it, it is just to make the changing of the password easier than having to recompile it everytime.

This is in VB.net. Also, there is no required user name for the application, just 1 textbox (TextBox1) that asks for the password.

I suppose the application (upon startup) should read the text file, grab the password, and save it into a string variable called "password".

Does anyone have any clue how to accomplish this? Any help would be much appreciated!

7 Years
Discussion Span
Last Post by djjavo

I do realize the security issues, but it is only for testing purposes. Thanks a lot, this seems like very good information!


password only eh?, i've seen this once, is your text file have this some kind of data with hidden indexes?

well i have this one,

on the form load event I use filestream to load the text file for my users and reading it and getting their indexes

the program only load the text file once, it's like putting the data on a temporary storage

and this following code reads the data and validate it

Private Function Registered_ID() As Boolean
        Dim n As Integer = 0
        Registered_ID = False 
        While Not Registered_ID And n <= 99
            If txtPassword.Text = UserIDs(n) Then
                Registered_ID = True
            End If
            n = n + 1
        End While
    End Function

Edited by aldeene: n/a


I'm not sure if this is what you are wanting, but I'll give it a try ;)

Dim password As String
Dim FileReader As New StreamReader(File.Open("path_to_passtext.txt", FileMode.OpenOrCreate))
        password = FileReader.ReadLine

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = password Then
                MsgBox("Incorrect Login Details, Please Re-enter")
            End If
    End Sub

That does the trick for me and I hope it works for you :D

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.