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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:25:46+00:00 2026-05-10T19:25:46+00:00

We have a current application where user login credentials are stored in a SQL

  • 0

We have a current application where user login credentials are stored in a SQL Server DB. These are, basically, stored as a plain text username, a password hash, and an associated salt for this hash.

These were all created by built in functions in ASP.NET’s membership/role system. Here’s a row for a user named ‘joe’ and a password of ‘password’:

joe,kDP0Py2QwEdJYtUX9cJABg==,OJF6H4KdxFLgLu+oTDNFodCEfMA=

I’ve dumped this stuff into a CSV file and I’m attempting to get it into a usable format for Django which stores its passwords in this format:

[algo]$[salt]$[hash]

Where the salt is a plain string and the hash is the hex digest of an SHA1 hash.

So far I’ve been able to ascertain that ASP is storing these hashes and salts in a base64 format. Those values above decode into binary strings.

We’ve used reflector to glean how ASP authenticates against these values:

internal string EncodePassword(string pass, int passwordFormat, string salt) {     if (passwordFormat == 0)     {         return pass;     }     byte[] bytes = Encoding.Unicode.GetBytes(pass);     byte[] src = Convert.FromBase64String(salt);     byte[] dst = new byte[src.Length + bytes.Length];     byte[] inArray = null;     Buffer.BlockCopy(src, 0, dst, 0, src.Length);     Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);     if (passwordFormat == 1)     {         HashAlgorithm algorithm = HashAlgorithm.Create(Membership.HashAlgorithmType);         if ((algorithm == null) && Membership.IsHashAlgorithmFromMembershipConfig)         {             RuntimeConfig.GetAppConfig().Membership.ThrowHashAlgorithmException();         }         inArray = algorithm.ComputeHash(dst);     }     else     {         inArray = this.EncryptPassword(dst);     }     return Convert.ToBase64String(inArray); } 

Eseentially, pulls in the salt from the DB and b64 decodes it into a binary representation. It does a ‘GetBytes’ on the raw password and then it concatinates them, salt first.

It then runs the SHA1 algorithm on this new string, base64 encodes it, and compares it against the value stored in the database.

I’ve attempted to write some code to try and reproduce these hashes in Python and I’m failing. I won’t be able to use them in Django until I can figure out how this translates over. Here’s how I’m testing:

import hashlib from base64 import b64decode, b64encode  b64salt = 'kDP0Py2QwEdJYtUX9cJABg==' b64hash = 'OJF6H4KdxFLgLu+oTDNFodCEfMA=' binsalt = b64decode(b64salt) password_string = 'password'  m1 = hashlib.sha1() # Pass in salt m1.update(binsalt) # Pass in password m1.update(password_string) # B64 encode the binary digest if b64encode(m1.digest()) == b64hash:     print 'Logged in!' else:     print 'Didn't match'     print b64hash     print b64encode(m1.digest()) 

I’m wondering if anyone can see any flaws in my approach or can suggest an alternate method. Perhaps you can take the algorithms above and the known password and salt above and produce the hash on your system?

  • 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. 2026-05-10T19:25:46+00:00Added an answer on May 10, 2026 at 7:25 pm

    It appears python is inserting a byte order marker when you convert a UTF16 string to binary. The .NET byte array contains no BOM, so I did some ghetto python that turns the UTF16 into hex, removes the first 4 characters, then decodes it to binary.

    There may be a better way to rip out the BOM, but this works for me!

    Here’s one that passes:

    import hashlib from base64 import b64decode, b64encode  def utf16tobin(s):   return s.encode('hex')[4:].decode('hex')  b64salt = 'kDP0Py2QwEdJYtUX9cJABg==' b64hash = 'OJF6H4KdxFLgLu+oTDNFodCEfMA=' binsalt = b64decode(b64salt) password_string = 'password'.encode('utf16') password_string = utf16tobin(password_string)  m1 = hashlib.sha1() # Pass in salt m1.update(binsalt + password_string) # Pass in password # B64 encode the binary digest if b64encode(m1.digest()) == b64hash:     print 'Logged in!' else:     print 'Didn't match'     print b64hash     print b64encode(m1.digest()) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer class Program { static void Main(string[] args) { Timer timer… May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Use GROUP_CONCAT SELECT GROUP_CONCAT(bar) FROM TABLE GROUP BY foo; May 11, 2026 at 10:50 pm
  • Editorial Team
    Editorial Team added an answer Your code doesn't work because the function is not returning… May 11, 2026 at 10:50 pm

Related Questions

Our SSO login process uses Forms Authentication against a custom user store in SQL
Is there a Win32 function I can call to show a Windows login dialog?
We have build a intranet application where users have to login to do certain
Using Windows 2003, I'm look for a way to create a logoff script that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.