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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:15:26+00:00 2026-05-11T19:15:26+00:00

I’m updating an old ASP/MySql webapp to ASP.NET/MS SQL. We would like to keep

  • 0

I’m updating an old ASP/MySql webapp to ASP.NET/MS SQL.

We would like to keep the logins from the old website working in the new app.

Unfortunately the passwords were stored in the MySql DB using MySql’s password() function.

Is it possible to simulate MySql’s password() function in either .NET or
MS SQL?

Any help/links are appreciated.

  • 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-05-11T19:15:26+00:00Added an answer on May 11, 2026 at 7:15 pm

    According to MySQL documentation, the algorithm is a double SHA1 hash. When examining the MySQL source code, you find a function called make_scrambled_password() in libmysql/password.c. The function is defined as follows:

    /*
        MySQL 4.1.1 password hashing: SHA conversion (see RFC 2289, 3174) twice
        applied to the password string, and then produced octet sequence is
        converted to hex string.
        The result of this function is used as return value from PASSWORD() and
        is stored in the database.
      SYNOPSIS
        make_scrambled_password()
        buf       OUT buffer of size 2*SHA1_HASH_SIZE + 2 to store hex string
        password  IN  NULL-terminated password string
    */
    
    void
    make_scrambled_password(char *to, const char *password)
    {
      SHA1_CONTEXT sha1_context;
      uint8 hash_stage2[SHA1_HASH_SIZE];
    
      mysql_sha1_reset(&sha1_context);
      /* stage 1: hash password */
      mysql_sha1_input(&sha1_context, (uint8 *) password, (uint) strlen(password));
      mysql_sha1_result(&sha1_context, (uint8 *) to);
      /* stage 2: hash stage1 output */
      mysql_sha1_reset(&sha1_context);
      mysql_sha1_input(&sha1_context, (uint8 *) to, SHA1_HASH_SIZE);
      /* separate buffer is used to pass 'to' in octet2hex */
      mysql_sha1_result(&sha1_context, hash_stage2);
      /* convert hash_stage2 to hex string */
      *to++= PVERSION41_CHAR;
      octet2hex(to, (const char*) hash_stage2, SHA1_HASH_SIZE);
    }
    

    Given this method, you can create a .NET counterpart that basically does the same thing. Here’s what I’ve come up with. When I run SELECT PASSWORD(‘test’); against my local copy of MySQL, the value returned is:

    *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29

    According to the source code (again in password.c), the beginning asterisk indicates that this is the post-MySQL 4.1 method of encrypting the password. When I emulate the functionality in VB.Net for example, this is what I come up with:

    Public Function GenerateMySQLHash(ByVal strKey As String) As String
        Dim keyArray As Byte() = Encoding.UTF8.GetBytes(strKey)
        Dim enc = New SHA1Managed()
        Dim encodedKey = enc.ComputeHash(enc.ComputeHash(keyArray))
        Dim myBuilder As New StringBuilder(encodedKey.Length)
    
        For Each b As Byte In encodedKey
            myBuilder.Append(b.ToString("X2"))
        Next
    
        Return "*" & myBuilder.ToString()
    End Function
    

    Keep in mind that SHA1Managed() is in the System.Security.Cryptography namespace. This method returns the same output as the PASSWORD() call in MySQL. I hope this helps for you.

    Edit: Here’s the same code in C#

    public string GenerateMySQLHash(string key)
    {
        byte[] keyArray = Encoding.UTF8.GetBytes(key);
        SHA1Managed enc = new SHA1Managed();
        byte[] encodedKey = enc.ComputeHash(enc.ComputeHash(keyArray));
        StringBuilder myBuilder = new StringBuilder(encodedKey.Length);
    
        foreach (byte b in encodedKey)
            myBuilder.Append(b.ToString("X2"));
    
        return "*" + myBuilder.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

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.