This document provides a tutorial on using the My.Settings property in VB.NET to store and retrieve username and password values. It demonstrates creating settings in the project properties, loading the values on form load, validating login by comparing entered values to settings, and updating the settings with new username and password values. The code samples show how to declare variables to hold the values, load labels with initial settings, validate login by comparing entered values, clear fields after login, and update settings with new values after changing account.
2. ◦ Introduction:
For student-developers out there, here is a tutorial about
the My.Setting in vb.net.
Here is a simple Log-in form which will surely help you in
your programs.
3.
4.
Once you already have your forms with all the
required textboxes, Labels, and buttons; see
the ‘Solution Explorer’ mostly at the upper
Right, then follow the images on the next
slides:
6. 3. Select
Settings,
4. Fill-up the
name and its
value,
Variables that will
hold the
username and
password
*note:
Remember the Names and its corresponding Values,
you will use it later.
7.
@ FORM LOAD:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
lblUserName.Text = My.Settings.UN
lblPassword.Text = My.Settings.PW
The names we
entered a while
back.
End Sub
This code will call the values that you entered in the properties,
In case you don’t remember the values, you can unhide the
labels from their properties.
8.
@ BUTTON LOGIN CLICKED:
Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnLogIn.Click
strInUN = txtUserName.Text
strInPW = txtPassword.Text
If strInUN = My.Settings.UN And strInPW = My.Settings.PW Then
Me.Hide()
Variables that will
Form2.Show()
hold the string
txtPassword.Clear()
value that you
txtUserName.Clear()
entered,
Else
MsgBox("User Name and Password mismatch", 0)
txtPassword.Clear()
txtUserName.Clear()
End If
Form2.txtNewPassword.Text = "New Password"
Form2.txtNewUserName.Text = "New User Name"
End Sub
*note:
Please Ensure that all variables are declared,
9. To check if the
@ CHANGE ACCOUNT CLICKED:
new password
Private Sub btnChangeAccount_Click(ByVal sender As System.Object, ByVal e As _
and verify
System.EventArgs) Handles btnChangeAccount.Click
password
strNewUN = txtNewUserName.Text
matched,
strNewPW = txtNewPassword.Text
If txtNewPassword.Text = txtVerifyPassword.Text Then
My.Settings.UN = txtNewUserName.Text
My.Settings.PW = txtNewPassword.Text
If strNewUN = "New User Name" Then
MsgBox("Please enter your NEW User Name", 0)
Setting the new
ElseIf strNewPW = "New Password" Then
username and
MsgBox("Please enter your NEW Password", 0)
password
Else
Me.Hide()
Form1.Show()
txtNewPassword.Clear()
txtNewUserName.Clear()
If the new
txtVerifyPassword.Clear()
password and the
End If
verification did
Else
not match,
MsgBox("Password mismatched", 0)
txtNewPassword.Clear()
txtVerifyPassword.Clear()
End If
Form1.lblUserName.Text = My.Settings.UN
To call the new
Form1.lblPassword.Text = My.Settings.PW
username and
End Sub
password at the
first form