PHP password_hash: overview
PHP's password_hash() function is the recommended way to store user passwords. By default it uses bcrypt, a deliberately slow algorithm that includes a random salt and a configurable cost factor, producing strings like $2y$10$… that are 60 characters long.
This tool generates genuine bcrypt hashes in your browser and can verify a plain password against an existing hash — handy for seeding a database, resetting an admin account or debugging a login that refuses to work.
How to use PHP password_hash
- Type the password you want to hash.
- Choose a cost factor (10–12 is typical in production).
- Copy the resulting $2y$ hash into your database or seed file.
- Use the verify mode to check whether a password matches a stored hash.
Implementing password hashing correctly in PHP
Always hash with password_hash() and check with password_verify(). Never compare hashes with == or build your own salting scheme; the built-in functions handle salts and timing-safe comparison for you.
Store the full 60-character string in a VARCHAR(255) column. The extra room lets PHP switch to longer formats such as Argon2id in the future without a schema change.
Use password_needs_rehash() after a successful login. When you raise the cost factor or change algorithm, users are upgraded transparently the next time they sign in.
Choose a cost that takes about 100–250 ms on your server. Each +1 doubles the work. Cost 12 is a sensible modern default on most hosting.
<?php
$hash = password_hash($plain, PASSWORD_BCRYPT, ['cost' => 12]);
if (password_verify($input, $hash)) {
if (password_needs_rehash($hash, PASSWORD_BCRYPT, ['cost' => 12])) {
$hash = password_hash($input, PASSWORD_BCRYPT, ['cost' => 12]);
// save the new $hash
}
// login OK
}Frequently asked questions
Why does the same password give a different hash each time?
Bcrypt generates a new random salt for every hash. password_verify reads the salt from the stored hash, so verification still works.
What is the difference between $2y$ and $2a$?
They are bcrypt variants; $2y$ is PHP's fixed version. Modern libraries accept both.
Can a bcrypt hash be decrypted?
No. Hashing is one-way. The only attack is guessing passwords, which bcrypt makes intentionally slow.
Should I use Argon2 instead?
Argon2id (PASSWORD_ARGON2ID) is excellent if your PHP build supports it. Bcrypt remains secure and universally available.
What is the PHP password_hash?
The PHP password_hash is a free online tool on trysandbox.io. In short: Bcrypt hashes compatible with PHP's password_hash() and password_verify(). It is part of our security collection and works directly in your web browser on desktop, tablet and phone, with no sign-up, no download and no usage limits.
People usually find this page when searching for terms like php, bcrypt, password_hash, encrypt, crypted, verify. Whatever brought you here, the goal is the same: get a correct result quickly, understand what the tool is doing, and know how to use the output with confidence. This guide explains exactly that.
Why use an online PHP password_hash?
Security tools help you create and inspect the building blocks of safe systems: strong secrets, hashes, keys, tokens and certificates. Getting these details right is the difference between an account that is hard to break into and one that falls to a simple automated attack.
Doing this work in the browser keeps sensitive values on your own device. Nothing you type needs to travel to a third-party server, which removes an entire class of risk compared with online tools that process data remotely.
The PHP password_hash is designed for developers, system administrators, IT teams, security-conscious individuals and students learning cryptography basics. You do not need technical knowledge to get started, but advanced users will find the options they need to fine-tune the result.
Common uses for the PHP password_hash
Here are some of the most common situations where the PHP password_hash is useful:
- Auditing whether an existing value meets modern strength recommendations
- Creating strong, unique secrets for accounts, servers and API integrations
- Checking or decoding tokens and certificates while debugging authentication
- Learning how hashing, encoding and encryption differ in practice
- Preparing configuration values for development and staging environments
Step-by-step: getting the best result
Start by deciding what level of strength you need, generate or paste the value, review the result, and copy it straight into its secure destination. Clear the page when you are finished, especially on shared computers.
If the result is not what you expected, change one option at a time and compare. Small adjustments are easier to understand than changing everything at once, and you will quickly learn which settings matter most for php password_hash tasks.
Tips and best practices
Follow these recommendations to get reliable, professional results from the PHP password_hash:
- Rotate keys and tokens on a schedule and immediately after any suspected exposure.
- Use a different secret for every account or service so one leak does not unlock everything.
- Store generated secrets in a password manager or a dedicated secrets vault, never in plain text files or chat messages.
- Prefer modern, slow password-hashing algorithms such as bcrypt or Argon2 for stored passwords; fast hashes like MD5 and SHA-1 are not suitable for that job.
Mistakes to avoid
Even experienced users run into these problems. Keep them in mind when working with the PHP password_hash:
- Confusing encoding (like Base64) with encryption — encoded data can be read by anyone.
- Pasting production secrets into tools you do not trust or into screenshots and tickets.
- Reusing short or predictable values because they are easier to remember.
Privacy and security
This tool runs entirely in your browser using built-in cryptographic functions where available. Your inputs are not uploaded or logged by this site. For extremely sensitive production keys, you can also disconnect from the internet after the page loads and the tool will keep working.
We built trysandbox.io around this principle because utility tools often handle personal or business information. Running the PHP password_hash locally means faster results, no waiting for uploads and no risk of your input being stored on someone else's server.
PHP password_hash: frequently asked questions
Do I need to install anything to use the PHP password_hash? No. It runs in any modern browser, including Chrome, Edge, Firefox and Safari, on Windows, macOS, Linux, Android and iOS. Just open the page and start working.
Does the PHP password_hash work on mobile? Yes. The layout adapts to small screens, and every control can be used with touch. For long inputs or large files, a laptop or desktop is more comfortable, but the result is the same.
Is my data saved? No. Nothing you enter into the PHP password_hash is stored on our servers. If you refresh or close the page, your input is cleared, so copy or download your result before leaving.
Can I use the result commercially? Yes. Output you create with the PHP password_hash is yours to use in personal, client and commercial work. You are responsible for checking that the final result is accurate and suitable for its purpose.
What should I do if something looks wrong? Double-check your input first, then try different options. If the problem continues, contact us through the Contact page with a short description and we will look into it.
Is the PHP password_hash free?
Yes. The PHP password_hash is completely free to use, as often as you like, for personal and commercial projects. There is no account, no watermark and no trial period. The site is supported by advertising, which keeps every tool available to everyone.
If you find the PHP password_hash useful, explore the related tools in the Security category — many tasks combine two or three tools, and they all share the same simple, private, browser-based approach.