Question

I have created a sample Login form in C# Windows Form Application and what I want is to add Remember username or password feature to my login form.

I just need to provide my username, cause it will remember my password and automatically fill in the password field (Ex. Like in gmail auth).

How could I achieve that?

This is my Login form app:- http://i50.tinypic.com/2pzxjb7.jpg

Was it helpful?

Solution

I would use .Net's built-in settings API.

You can define multiple strongly typed settings with customizable scope; user or application. There is an interface for it in Visual Studio. If you open the project properties, you can select the settings tab. If you don't have a settings file in your project, you can click the link here to have Visual Studio create one. Once you have one, you can enter in the names, types, scope, and default values of your application settings.

After you set all this up, you will have a class called Settings under the <ProjectName>.Properties namespace. You can then use the Settings.Default static property to access the default settings, change their values, and call the Save method to persist them.

When you start your app up, the persisted settings are loaded and you could programmatically enter them into your user interface.

If all of this is over-kill for your scenario, you could just manually read/write to/from a file in a defined location relative to the user's profile folder.

OTHER TIPS

I solved using that.

In you winforms project right click and go to properties, select settings and add name to store data (eg. userName and passUser)

So in you login form add a checkbox remember me.

In you button loggin check if checkbox true, save user and pass

        if (checkRemember.Checked)
        {
            Properties.Settings.Default.userName = textBoxUserName.Text;
            Properties.Settings.Default.passUser = textBoxUserPass.Text;
            Properties.Settings.Default.Save();
        }

In you load login form add this

        if (Properties.Settings.Default.userName != string.Empty)
        {
            textBoxUserName.Text = Properties.Settings.Default.userName;
            textBoxUserPass.Text = Properties.Settings.Default.passUser;
        }

Regards.

You can try with cookie base remember password

check below reference :

https://www.aspforums.net/Threads/130530/Save-Username-and-Password-in-Cookies-using-C-in-ASPNet/

you can store it in the registry, or database or in a application settings. But I'm not sure how secure you want.

http://msdn.microsoft.com/en-us/library/ms973902.aspx

if (checkRemember.Checked)
{
    Properties.Settings.Default.userName = textBoxUserName.Text;
    Properties.Settings.Default.passUser = textBoxUserPass.Text;
    Properties.Settings.Default.Save();
}

if (Properties.Settings.Default.userName != string.Empty)
{
   textBoxUserName.Text = Properties.Settings.Default.userName;
   textBoxUserPass.Text = Properties.Settings.Default.passUser;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top