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

  • Home
  • SEARCH
  • 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 8020811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:47:43+00:00 2026-06-04T21:47:43+00:00

I’ve been debugging this code for hours, I think I would benefit from someone

  • 0

I’ve been debugging this code for hours, I think I would benefit from someone else taking a look at the problem. I’m writing a login system for my software in C# .net. I am encoding the passwords in SHA512. I am using the hashing algorithm written by Rush Frisby.

Additionally, I am using a salt and pepper on the users password.

// Form1.cs (inside button1_Click)

        // IsConnected is a variable which holds the state of the connection
        // to the server
        if (IsConnected == true)
        {
            UsernameField = textBox1.Text;                  // Fetch the username
            PasswordField = textBox2.Text;                  // Fetch the password

            // The per-user salt is stored in the DB, go get it:
            Salt = MH.GetUserSalt(UsernameField);           // Get the salt for the user

            // Encrypt the salt, pepper and secret keys in SHA512
            Salt = HH.SHA512(Salt);                 // The salt is stored in the DB
            Pepper = HH.SHA512(Pepper);             // The salt is a private field in the current class
            SecretKey = HH.SHA512(Salt + Pepper);   // The secret key = SHA512(Salt + Pepper)

            // Now, with the secret key let's add that to the password after it's encrypted
            PasswordField = SecretKey + (HH.SHA512(PasswordField));     // The password is now secret key + SHA512(password)

            // I am expecting 1 row back from the database:
            success = MH.CheckUser(UsernameField, PasswordField);       // success (bool): Did CheckUser return 1 row?

[SPACER]

// MySQLHelper.cs
    public bool CheckUser(string username, string password)
    {
        if (IsConnected != true)
        {
            LastError = "Not connected!";
            return false;
        }

        cmd = connection.CreateCommand();
        cmd.CommandText = "SELECT * FROM credentials WHERE Username = '" + username + "' AND Password = '" + password + "'";

        rdr = cmd.ExecuteReader();

        rows = 0;
        while (rdr.Read())
        {
            rows++;
        }

        // Gracefully release resources (rdr)
        ReleaseResources();

        if (rows == 1)
            return true;
        else
            return false;
    }

This always works on the first attempt to login (granted I provide legitimate credentials), however if I fail the first attempt, the second attempt (and any corresponding attempts) will always return 0 (rows), even if the credentials are good (which should return 1 row). If I close out the application and reopen it, the same thing happens. I’m able to login, but I must provide good credentials on the first attempt or else the rest won’t work.

As I have mentioned, I have isolated the issue down to the password fields not matching. This is the stage in which the secret key is added to the sha512 encoded user password. Let me give you an example:

Valid (on first attempt):
“B045B1FA1FCD4450D34EEEF17414E334B9E928EDB076E3D3D1EE8AF4EF25FD4076B6B228EA4AC53136FDF2BFF3FF780096EA5A63851EADB6133EB537C61CA23ECBE0CD68CBCA3868250C0BA545C48032F43EB0E8A5E6BAB603D109251486F77A91E46A3146D887E37416C6BDB6CBE701BD514DE778573C9B0068483C1C626AEC”

Valid (on second attempt, but remember it fails):
“B1316286A4628120FF77A53CE11CE0B16DF49358858729E3D01B25CDAFB5194112C982B11AC08424C6637F8F445D2D7A76A41B4857B43D60A54BD9E67FC14F20CBE0CD68CBCA3868250C0BA545C48032F43EB0E8A5E6BAB603D109251486F77A91E46A3146D887E37416C6BDB6CBE701BD514DE778573C9B0068483C1C626AEC”

As you can see, for some reason the password is being altered. Do you know what it could be? I appreciate all the help!

C#
Windows 7 x64
Visual Studio 11
MySQL Connector Net 6.5.4

If there is any additional information I can provide you with that I have accidently withheld, please tell me.

  • 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-04T21:47:45+00:00Added an answer on June 4, 2026 at 9:47 pm

    The first part of the string is different, so your salt or pepper has changed.
    The password is still good, because the last part of the strings are still equal.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.