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!

This of course is a security nightmare, but if you ask for it:
For 1 field and 1 value, I find it easier to use application settings.
You'll need a simple form to see and change the password and a setting created in application parameters.
Here's an example about settings: http://www.daniweb.com/software-development/vbnet/code/296812

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

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
        FileReader.Close()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = password Then
            NextForm.Show()
            Me.Hide()
        Else
                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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.