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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:46:02+00:00 2026-05-13T15:46:02+00:00

I stumbled across BCrypt.net after reading Jeff Atwood’s post about storing passwords which led

  • 0

I stumbled across BCrypt.net after reading Jeff Atwood’s post about storing passwords which led me to Thomas Ptacek’s recommendation to use BCrypt to store passwords. Which finally led me to this C# implementation of BCrypt

In the comments on the last link above someone asked “Why do GenerateSalt(30) take for ever, but GenerateSalt(31) seems to take no time at all?”

I ran BCrypt.HashPassword(password, BCrypt.GenerateSalt(31)) and got my result in 0 milliseconds.

I’ve been running BCrypt.HashPassword(“password”, BCrypt.GenerateSalt(30)) for over 5 minutes now and still do not have a result.

I realize we’ll probably not need a randomly generated 30 character salt to create our password hashes (or irreversible encryption in BCrypt’s case) for years. EDIT I should have read the code a bit, logRounds doesn’t have anything to do with the salt length. Thanks Aaronaught.

So, why does GenerateSalt(31) return a value almost instantly (when it should take about twice as long as GenerateSalt(30)?

UPDATE

here is the fix:

private byte[] CryptRaw(byte[] password, byte[] salt, int logRounds) {
    // ... snip ...
    uint rounds = 1U << logRounds;
    // ... snip
}
  • 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-13T15:46:03+00:00Added an answer on May 13, 2026 at 3:46 pm

    I suspect that the bug is here:

    private byte[] CryptRaw(byte[] password, byte[] salt, int logRounds) {
        // ... snip ...
        int rounds = 1 << logRounds;
        // ... snip
    }
    

    When you specify 31 for the logRounds, it computes that as 2^32, which can’t fit in an int and overflows, so the hash is actually done in… er, zero passes. The author should have used uint instead. Easy to fix!


    Also wanted to comment on this:

    I realize we’ll probably not need a randomly generated 30 characters salt to create our password hashes…

    Note that the logRounds parameter does not refer to the number of characters/bytes in the salt, which is always 16. It refers to the logarithmic base of the number of passes that the hash will take to compute; in other words it’s a way to make bcrypt scale with Moore’s Law, making the function several orders of magnitude more expensive to compute if computers ever get fast enough to crack existing hashes.

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

Sidebar

Related Questions

I've stumbled across this great post about validating parameters in C#, and now I
I stumbled across this article which was talking about AJAX and jQuery and I
I recently stumbled across this entry in the google testing blog about guidelines for
I'm trying out ASP.NET MVC routing and have of course stumbled across a problem.
Today I stumbled about a Problem which seems to be a bug in the
I stumbled across a post on here regarding connecting to a DB with JavaScript.
When reading Wikipedia's entry on Haskell 2010 I stumbled across this: -- using only
I've recently stumbled across a few blogs that say the ASP.NET Ajax Library is
NHydrate is a lesser-known ORM for .Net - I stumbled across it for the
I stumbled across the following warning when I was reading Code Like a Pythonista:

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.