Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:26:36+00:00 2026-06-14T15:26:36+00:00

I’m a newbie to Windows Forms. I’m designing an Windows Application in .Net Framework

  • 0

I’m a newbie to Windows Forms.

I’m designing an Windows Application in .Net Framework 2.0 in which,
I need to Store a UserName and Password somewhere in the System and access them every time I open My Application and Some times I need to change those credentials on User command.

I heard registry is the Best way in doing so. I know Nothing About Using Registry in C# .Net.

So Can you Help me in

How To Get Values which are In Registry, and how to Set a Value to Registry. ??

I’m Using .Net Framework 2.0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:26:37+00:00Added an answer on June 14, 2026 at 3:26 pm

    The subject is very broad. You should start reading on MSDN about the class

    Microsoft.Win32.RegistryKey

    But I really suggest to avoid the registry altogether.
    Allowing the registry to store configuration info for normal applications has been a mistake from the start by Microsoft.

    You could write a simple hashing function, apply it to your username and password and store the result in a file located in the ApplicationData folder.
    At the next run check if the file exist, read it and compare its content with the hashing of username and password.

    Here a rough example, just to let you start on your own code.

    private void button1_Click(object sender, EventArgs e)
    {
        string user = "Steve";
        string pass = "MyPass";
    
        string hashedUser = GetHashedText(user);
        string hashedPass = GetHashedText(pass);
    
        string file = Path.Combine(Environment.GetFolderPath 
                           (Environment.SpecialFolder.ApplicationData), 
                           "MyKeys.txt");
    
        if (File.Exists(file))
        {
            using (StreamReader sr = new StreamReader(file))
            {
                string recordedUser = sr.ReadLine();
                string recordedPass = sr.ReadLine();
                if (recordedUser == user && recordedPass == pass)
                    MessageBox.Show("User validated");
                else
                    MessageBox.Show("Invalid user");
            }
        }
        else
        {
            using (StreamWriter sw = new StreamWriter(file, false))
            {
                sw.WriteLine(hashedUser);
                sw.WriteLine(hashedPass);
            }
    
        }
    }
    
    private string GetHashedText(string inputData)
    { 
        byte[] tmpSource;
        byte[] tmpData;
        tmpSource = ASCIIEncoding.ASCII.GetBytes(inputData);
        tmpData = new MD5CryptoServiceProvider().ComputeHash(tmpSource);
        return Convert.ToBase64String(tmpData);
    }
    

    EDIT: Based on your comment, it seems that you need a crypt and decrypt function. The code below is taken and adapted from the Extension Overflow, where you can find other useful methods.
    Now, before write to disk, call the Encrypt method with the string to encrypt and a key. After reading, call the Decrypt method passing the crypted text and the secret key.

    string cryptedUser = Encrypt(user, "your_secret_key_ABCDEFG");
    ....
    
    public string Encrypt(string stringToEncrypt, string key)
    {
        if (string.IsNullOrEmpty(stringToEncrypt))
            throw new ArgumentException("An empty string value cannot be encrypted.");
        if (string.IsNullOrEmpty(key))
            throw new ArgumentException("Cannot encrypt using an empty key.");
    
        CspParameters cspp = new CspParameters();
        cspp.KeyContainerName = key;
        RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspp);
        rsa.PersistKeyInCsp = true;
        byte[] bytes = rsa.Encrypt(UTF8Encoding.UTF8.GetBytes(stringToEncrypt), true);
        return BitConverter.ToString(bytes);
    }
    
    string clearText = Decrypt(cryptedText, "your_secret_key_ABCDEFG");
    ....
    
    public string Decrypt(string stringToDecrypt, string key)
    {
        string result = null;
        if (string.IsNullOrEmpty(stringToDecrypt))
            throw new ArgumentException("An empty string value cannot be encrypted.");
        if (string.IsNullOrEmpty(key))
            throw new ArgumentException("Cannot decrypt using an empty key");
        try
        {
            CspParameters cspp = new CspParameters();
            cspp.KeyContainerName = key;
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cspp);
            rsa.PersistKeyInCsp = true;
            string[] decryptArray = stringToDecrypt.Split(new string[] { "-" }, 
                                     StringSplitOptions.None);
            byte[] decryptByteArray = Array.ConvertAll<string, byte>
                                     (decryptArray, (s => Convert.ToByte(byte.Parse(s,
                                     System.Globalization.NumberStyles.HexNumber))));
            byte[] bytes = rsa.Decrypt(decryptByteArray, true);
            result = System.Text.UTF8Encoding.UTF8.GetString(bytes);
        }
        finally
        {
            // no need for further processing
        }
        return result;
    }
    

    Of course, I assume that the security level required by your application allows that username ans passwords will be stored in the local system. (And as you know, everything that is stored on the local system is not very secure)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.