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 9052761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:15:37+00:00 2026-06-16T13:15:37+00:00

I am currently working on a visual studio C# windows form project. However, I

  • 0

I am currently working on a visual studio C# windows form project. However, I am confused by how SHA256 + salted works. I found some examples online but unable to understand how can I call this function.

I would like to call this function in a login form connecting to a database (Microsoft Access 2010).

  • How do I call this function by a click of a button and reading the
    password from a Textbox?
  • How do i display out the hash value in a
    Messagebox.Show method? (For my testing purpose)
  • Is it possible to
    compare two text (hashed and salted) and giving a positive result?

    public static string sha256encrypt(string phrase, string UserName)
    {
        string salt = CreateSalt(UserName);
        string saltAndPwd = String.Concat(phrase, salt);
        UTF8Encoding encoder = new UTF8Encoding();
        SHA256Managed sha256hasher = new SHA256Managed();
        byte[] hashedDataBytes =      sha256hasher.ComputeHash(encoder.GetBytes(saltAndPwd));
        string hashedPwd = String.Concat(byteArrayToString(hashedDataBytes), salt);
        return hashedPwd;
    }
    
    public static string byteArrayToString(byte[] inputArray)
    {
        StringBuilder output = new StringBuilder("");
        for (int i = 0; i < inputArray.Length; i++)
        {
            output.Append(inputArray[i].ToString("X2"));
        }
        return output.ToString();
    }
    
    private static string CreateSalt(string UserName)
    {
        string username = UserName;
        byte[] userBytes; 
        string salt;
        userBytes = ASCIIEncoding.ASCII.GetBytes(username);
        long XORED = 0x00; 
    
        foreach (int x in userBytes)
            XORED = XORED ^ x;
    
        Random rand = new Random(Convert.ToInt32(XORED));
        salt = rand.Next().ToString();
        salt += rand.Next().ToString();
        salt += rand.Next().ToString();
        salt += rand.Next().ToString();
        return salt;
    }
    

How do I create an SHA256 hash with salt?

shavalue = (sha256encrypt("password", "username");
saltedandhashtext = CreateSalt(shavalue);
  • 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-16T13:15:39+00:00Added an answer on June 16, 2026 at 1:15 pm

    For the first question look at CC Inc’s answer.

    To the second point:
    MessageBox.Show(sha256encrypt(textBox1.Text, "SampleUserName"));

    3) Yes, it is.

    You can compare two strings with the == comparator or string.Equals().

    public bool compareHashs(string hash1, string hash2){
       if(hash1.Equals(hash2) //or hash1 == hash2
          return true;
       }else{
          return false;
       }  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a long-term project for which I need Visual Studio
I am now working on a visual studio package project, currently all our tests
I am working in Visual Studio 2008 and have a Windows Forms project +
I'm working with winforms on Windows 7, using C# in Visual Studio 2010. Currently
I'm currently working on a C#/.NET project in Visual Studio 2010. The target framework
I'm using Visual Studio 2008. I'm currently working with WPF and I'm using Edit->Format
i m currently working on visual c++ 2008 express edition.. in my project i
I'm using Visual Studio 2005 for a project I'm working on right now. I've
I am currently working on a Windows form application. How can i create the
I'm currently working on a project using Windows Mobile 5.0 (I know i'ts preety

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.