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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:42:52+00:00 2026-05-24T22:42:52+00:00

Normally if I have a password, I would use this pseudocode: $password = this

  • 0

Normally if I have a password, I would use this pseudocode:

$password = "this is the user's password";
/***/
$salt = GenerateSalt();
$hash = Hash($password);
$hash = Hash($hash . $salt);

However, as I understand it, PHP has a crypt() function which takes a salt as well as the number of iterations of a particular algorithm. Apparently you are.. supposed to pass the returned hash of crypt back into crypt as the salt. I do not understand this.

Can anyone please clarify how crypt works? Do I still need to append my own salt and rehash? In that case, would I just use a fixed salt for crypt, and then generate a separate crypt for each user? Or does crypt’s $salt parameter take care of that for 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-05-24T22:42:52+00:00Added an answer on May 24, 2026 at 10:42 pm

    The output of crypt consists of:

    • (optionally an algorithm identifier + load factor)
    • the salt for the used algorithm
    • the real hash

    When you pass this output als “salt” back to crypt, it will extract the right algorithm and salt, and use these for the operation. If there is only an algorithm mentioned, it uses this one and generate random salt. Otherwise it will choose a default algorithm and generate random salt. The hash part in the passed salt parameter is ignored.

    So you can simply compare your stored_hash with crypt(password, stored_hash) – if it is equal, it quite likely was the right password.

    Here is an pseudocode explanation (in PHP-like syntax) how crypt works:

    function crypt($password, $salt)
    {
      if (substr($salt,0 1) == "_") {
         $count = substr($salt, 1, 4);
         $real_salt = substr($salt, 5, 4);
         return "_" . $count . $real_salt . crypt_ext_des($password, $count, $salt);
      }
      if(substr($salt, 0, 3) == "$1$") {
         list($ignored, $real_salt, $ignored) = explode("$", $salt);
         return "$1$" . $real_salt . "$" . crypt_md5($password, $real_salt);
      }
      if(substr($salt, 0, 4) == "$2a$") {
          $cost = substr($salt, 4, 2);
          $real_salt = substr($salt, 7, 22);
          return "$2a$" . $cost . "$" . $real_salt . crypt_brypt($password, $real_salt, $cost);
      }
      // ... SHA256 and SHA512 analogons
    
      // no match => STD_DES
      $real_salt = substr($salt, 0, 2);
      return $real_salt . crypt_std_des($password, $real_salt);
    }
    

    The individual crypt_xxx functions then do the real work, depending on the algorithm.
    (Actually, the generation of random salt is missing in this description. It will be done if the $real_salt is empty.)

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

Sidebar

Related Questions

Normally we have login page with username, password filed and signin button. Using the
I'm doing this query: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() I normally have an aggregate field in my model
I have normally hand written xml like this: <tag><?= $value ?></tag> Having found tools
Normally I would have one junit test that shows up in my integration server
So I have this $name = $_GET['fullname']; $username = $_GET['username']; $password = $_GET['password']; $gender
I normally have several problems with how cron executes scripts as they normally don't
I have a set of 10 CSV files, which normally have a an entry
Normally when I have a private field inside a class or a struct, I
Normally when you have a application configuration file in your application and your application
I have a winforms application that normally is at about 2-4% CPU. We are

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.