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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:53:25+00:00 2026-06-16T00:53:25+00:00

I know PHP 5.5 is in alpha but this class I am making is

  • 0

I know PHP 5.5 is in alpha but this class I am making is just being made in advance to utilize it’s hashing feature by using function_exists().

I checked out the password_hash documentation. The 3rd argument is for $options which currently supports two options, ‘salt’ and ‘cost’.

It states the following:

cost, which denotes the algorithmic cost that should be used. Examples
of these values can be found on the crypt() page.

When I go to the crypt() page the documentation it gives is:

Blowfish hashing with a salt as follows: “$2a$”, “$2x$” or “$2y$”, a
two digit cost parameter, “$”, and 22 digits from the alphabet
“./0-9A-Za-z”. Using characters outside of this range in the salt will
cause crypt() to return a zero-length string. The two digit cost
parameter is the base-2 logarithm of the iteration count for the
underlying Blowfish-based hashing algorithmeter and must be in range
04-31, values outside this range will cause crypt() to fail. Versions
of PHP before 5.3.7 only support “$2a$” as the salt prefix: PHP 5.3.7
introduced the new prefixes to fix a security weakness in the Blowfish
implementation. Please refer to » this document for full details of
the security fix, but to summarise, developers targeting only PHP
5.3.7 and later should use “$2y$” in preference to “$2a$”.

I can’t seem to get my head wrapped around this. It says PHP 5.3.7 and later should use $2y$, but what cost value do I use to get that one and is it the best value to choose? The example they provide uses a value of 7, but according to the above it can go up to 31, what difference does it make to use say 4 opposed to say 31?

  • 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-16T00:53:26+00:00Added an answer on June 16, 2026 at 12:53 am

    The function password_hash() is just a wrapper around the function crypt(), and shall make it easier to use it correctly. It takes care of the generation of a safe random salt, and provides good default values.

    The easiest way to use this function would be:

    $hash = password_hash($password, PASSWORD_DEFAULT);
    

    That means, the function will hash the password with BCrypt (algorithm 2y), generates a random salt, and uses the default cost (at the moment this is 10). These are good default values, particularly i would not recommend generating the salt of your own, it is easy to make mistakes there.

    Should you want to change the cost parameter, you can do it like this:

    $hash = password_hash($password, PASSWORD_BCRYPT, ["cost" => 11]);
    

    Increasing the cost parameter by 1, doubles the needed time to calculate the hash value. The cost parameter is the logarithm (base-2) of the iteration count, which means:

    $iterations = 2 ^ $cost;
    

    Edit:

    I missed the point, that you want to generate your own class. For PHP version 5.3.7 and later, there exists a compatibility pack, from the same author that made the password_hash() function. You can either use this code directly, or look at the well crafted implementation. For PHP versions before 5.3.7 there is no support for crypt with 2y, the unicode aware BCrypt algorithm. You can instead use 2a, which is the best alternative for earlier PHP versions. I did an example with a lot of comments, maybe you want to have a look at it too.

    P.S. The expressions "salt" and "cost factor" are used correctly in password_hash(), the crypt() function though, uses the word salt for all crypt parameters together, that’s a bit misleading.

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

Sidebar

Related Questions

I know php is server-side, but is there a way to make this window
I'm getting this syntax error and I know it's PHP 101, but I wouldn't
I know php but I need to write a joomla addon by using joomla
I know PHP 5 already supports SQLite but for some reason I can't get
I know (PHP's) var_dump is supposed to be human readable and all, but analyzing
Pretty basic programming question, I know PHP have a function for it, but does
I wanted to know how PHP would execute this. Order of operations addslashes(strip_tags($record['value'])); Is
I know PHP but I do not know Python. I need to install a
I know PHP has call_user_func , I was just wondering if JavaScript had something
I know PHP a little. But Python is totally new for me. I only

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.