Hi every one !
I have two form : First Form for enter username and pass and Form2(Main Form). I want to save or register password and username if the user enter a valid pass . And for the next time , if the user execute this app , go to the Main Form(Form2) directly.
(because for the first time he enter a valid pass).
thanks for any help !

Recommended Answers

All 7 Replies

Member Avatar

Is your application using Forms based authentication or Windows Integrated authentication? I'm guessing it is forms based and so you will need to use a cookie to store "saved passwords" that will allow your users to return to the site without being prompted to login again after their session has expired. Here is an MSDN article that discusses Cookies and ASP.NET http://msdn.microsoft.com/en-us/library/ms178194.aspx

thanks , but it's a windows application .

You could get the encrypt the username and password and save it to Application.Settings, then on load decrypt it and compare it with whatever you want.

You could also encrypt it and store it in the system registry.
You could just set a value somewhere in the registry to let the program know the password was previously accepted.

You could also encrypt it and store it in the system registry.

how can I do it ? plz help !

If you decide to modify your registry or the registry of your users, I assume no liability.

First: Here is a link describing registry entries.

Here, now is a class that can be used for a simplified technique to do what you want.
On the first run, it asks the user to log in.
After the login (fake-login), it writes a value to HKCU that is retrieved on subsequent runs so the user does not need to log in anymore.

You will need to use your own design if you want the login to expire after a time or if you want the key to be encrypted.

This assumes the current user can write to HKCU.

using System;
using System.Linq;
using Microsoft.Win32;

namespace DW_413000_CS_CON
   public class CRegHelper
      private RegistryKey _regBaseKey = null;

      public CRegHelper()
         _regBaseKey =

      public void WriteKeyValToRegistry(string strKey, string strValue)
         _regBaseKey.SetValue(strKey, strValue);

      public string ReadValueFromRegistry(string strKey)
         if (!_regBaseKey.GetValueNames().Contains(strKey))
            return "Not Active";

         return _regBaseKey.GetValue(strKey).ToString();

   class Program
      static void Main(string[] args)
         CRegHelper regHelper = new CRegHelper();

         // See if user has passed login validation previously.
         string strActive = regHelper.ReadValueFromRegistry("Prog132");
         if (!strActive.Equals("Active_bb2d")) // made-up key
            // Show Log-in screen
            Console.Write("User must log in: ");
            // Do Login
            if (string.IsNullOrEmpty(Console.ReadLine()))
               Console.WriteLine("Login failed");
            regHelper.WriteKeyValToRegistry("Prog132", "Active_bb2d");

         Console.WriteLine("User is logged in.");

also you can use settings, but they are not that secure. using settings you have variables and then you can check those variables and if they are correct, proceed to the main form, if not, ask for credentials again.

Be a part of the DaniWeb community

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