I'm creating a file that will only be on my local machine, for personal use. To make sure my kids don't enter data (or delete it) I want to do a simple password protection feature. I basically just want, when a button is pressed, a box to pop up with a text field that a password is entered into. If whatever is entered doesn't match up to the hardcoded password "1234" (or whatever) then it won't allow the operation to proceed. If it does, then the process continues. How on earth would I do this?

I can do message boxes, but don't know where to start with this.

you can start with write file and read file into text file. use read file to check password...

I'm not even sure how to go about bringing up a box when the button is pressed to ask for user input into it. (Don't even know what that pop-up box would be called)...

Also, couldn't I just do something like
If val(userinput) = 123 Then
continue to write to file
Else
messageBox... ?

hmmm...
- you want to use text file to save password or you want to set password direct from coding (not change able) ??
if i see your code, i guess u want to use password in code. if just for personal use pasw in code more faster but it couldn't to change.

Yeah, I'm just wanting to put the password in the code. I'm not worried about being able to change it. Like I said, I'm mostly just wanted to ensure that my kids can't mess with the info.

When either of the 2 buttons are pressed, I'd like something similair to a message box to come up that just asks for the password and has a text box to enter it into.

When either of the 2 buttons are pressed

what buttons? login and ? or what ?

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        If txtPassword.text = "" Then
            MsgBox("Input Password", MsgBoxStyle.Critical, "Password text field empty")
            txtpassword.Focus()
        Else
            If txtpassword.Text = "1234" Then
                'continue to write file
            Else
                MsgBox("Wrong Password", MsgBoxStyle.Critical, "Wrong Password")
                txtpassword.Clear()
                txtpassword.Focus()
            End If
        End If
    End Sub

If your using visual basic 2008 express edition or even older versions i think, it can give you a login form template.
Setting it Up
1. In the solution Explorer right click your project name > add > windows form > login form.
2. Go to Project > 'project name' properties > Change the Shutdown Mode to "When last form Closes" and Change the Startup Form to "loginform1"

**Before you continue since from your post you only wanted a password just delete the username texbox.

Now you should have the design all done, but you will still need the code to do the actual work.
Code
1. Double-click OK in the login form and paste in:

'validates the password, if true shows program, else creates a messagebox saying its the wrong password
        If PasswordTextBox.Text = "1234" Then Form1.Show() Else MsgBox("Wrong Password", MsgBoxStyle.Critical, "Wrong Password")
        'if password is true closes itself
        If PasswordTextBox.Text = "1234" Then Me.Close()

Now it should work fine :);)

This article has been dead for over six months. Start a new discussion instead.