Question Need help with "Remember Me" Button

fantity

Active member
Joined
Mar 10, 2012
Messages
27
Programming Experience
Beginner
I want to make a remember me button for my login form. I have two settings already set which are Username and Password. They are both strings. I also need to know how to close a form and open another. Here is my login button code:
VB.NET:
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If CheckBox1.Checked Then
            My.Settings.Password = PasswordTextBox.Text
            My.Settings.Username = UsernameTextBox.Text


        End If


        Form1.Show()
        Me.Hide()
    End Sub
This is my form load code:
VB.NET:
CheckBox1.CheckState = CheckState.Checked
        UsernameTextBox.Text = My.Settings.Username
        PasswordTextBox.Text = My.Settings.Password

Whenever I click remember me and restart it it shows blank text boxes.
 
To save the settings that you have set, make sure that you are either: calling My.Settings.Save() or you have the "Save My.Settings on Shutdown" in the Project Properties checked (under Application). And if you have "Save My.Settings on Shutdown" checked already, make sure your application is exiting correctly.

Here's a quick link to MSDN about My.Settings: Accessing Application Settings (Visual Basic)

There are a bunch of different ways you use to close a form and open another. To close a form you can use it's Close method; to open, you can call the Show or ShowDialog method. You can create a new form object or you can call it by the class as well.
 
To save the settings that you have set, make sure that you are either: calling My.Settings.Save() or you have the "Save My.Settings on Shutdown" in the Project Properties checked (under Application). And if you have "Save My.Settings on Shutdown" checked already, make sure your application is exiting correctly.

Here's a quick link to MSDN about My.Settings: Accessing Application Settings (Visual Basic)

There are a bunch of different ways you use to close a form and open another. To close a form you can use it's Close method; to open, you can call the Show or ShowDialog method. You can create a new form object or you can call it by the class as well.

Thanks, the remember me button works, but is there anyway to close the a form without hiding it? Because when I am done and close form1, loginform1 is still open.
 
VB.NET:
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If CheckBox1.Checked Then
            My.Settings.Password = PasswordTextBox.Text
            My.Settings.Username = UsernameTextBox.Text


        End If


        Form1.Show()
        Me.Hide()
    End Sub
is there anyway to close the a form without hiding it? Because when I am done and close form1, loginform1 is still open.

How are you closing the form? Are you using the Hide method like shown in your previous post? Use the Close method to close it, also if you are closing the starting form and opening another form, make sure that in your Project Properties under that Applications tab you have the 'Close on last form exit' selected and not 'Close on start form exit', or vice versa depending on what you need.
 
That is not the way to implement "remember me" functionality. You're going to save a password in the user config file as plain text where anyone can see it?

that's a good point you brought up. I too have used the My.Settings to store a password before, well, i encrypt it first, but the encrypted text is still stored in the user config file. How would you have implemented it, or what would you suggest?
 
Sometimes you need to store sensitive data in the config file but the ability to encrypt sections of the config file is built into .NET. See here for more information on that:

Protected Configuration (Encrypting Config Files)

I would assume that that works for user config files as well as application config files, although I've never tested that theory.

That said, you should avoid storing sensitive information if you don't have to, and "remember me" functionality does not require it. The way it works with web sites is that the web server sends a cookie to the client that contains a session ID. That session will be either set to expire or not. The server decides that. When the clients sends the session ID to the server it is checked to see whether that session is expired or not and, if it is, a login is required. You can implement something similar in Windows applications. When a user logs in you create a session ID and store it both on the server, i.e. in the database, and on the client, i.e. in My.Settings or somewhere else appropriate. If the user says "remember me" then the session is flagged as not expiring.

Having typed all that, it does occur to me that the OP may be talking about something different. Does this question relate to the functionality that web sites provide, where you don't have to log in the next time you visit, or the functionality that browsers provide, where they remember the password for a particular user name so that you don't have to type it? If it's the former then it's something that should be built into the server side of the application, not just the client.
 
Back
Top