Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Security asks you to pick a password hashing policy for all applications in the company, including cost parameters. How would you decide and keep it current?

I would choose an adaptive algorithm that every stack in the company supports well, usually Argon2id with bcrypt or PBKDF2 as allowed alternatives where libraries or compliance require them. The cost is set by measuring one hash on production hardware against our peak login rate, and every stored value carries its algorithm and parameters so it can be upgraded on login. We review the numbers on a schedule, and in the long run reduce how many applications store passwords at all.

Why this question is asked

A company-wide password policy sounds like one line in a standard, but it has to work for Java, Node, Python and .NET teams, for a login service that handles hundreds of logins per second, and for a future where today's parameters are too weak. Interviewers ask this of senior engineers to see whether they can turn security advice into a decision that teams can follow and that stays correct over time. In this answer, we will choose the algorithm, set the cost by measurement, make every hash upgradeable, plan the regular review, and look at the strategic step of storing fewer passwords.

1A Quick Recap of What the Policy Must Achieve

A password hash protects users when the database leaks. The attacker then guesses passwords offline, as fast as their hardware allows, so the only defences are a salt (a random value per password, which stops precomputed tables and shared work) and a work factor (deliberate slowness, so each guess costs time and, for memory-hard functions, memory).

An adaptive function is one whose work factor we can raise as hardware gets faster. bcrypt, scrypt, Argon2 and PBKDF2 are adaptive; SHA-256 and MD5 are not. So the policy has three decisions: which adaptive function, which parameters, and how we change both over time.

2Choosing the Algorithm

Argon2id is the current first recommendation of most guidance, because it is memory-hard: each guess needs a block of memory, which makes GPU and custom-hardware attacks much more expensive. But a policy is only useful if every team can follow it with a well-maintained library. So we check support across our stacks before we decide. In Spring Security, Argon2PasswordEncoder exists but needs Bouncy Castle; BCryptPasswordEncoder needs nothing extra.

Some environments add constraints. Systems that must use FIPS-validated cryptography often have to use PBKDF2. bcrypt only uses the first 72 bytes of a password. The policy can therefore name a preferred algorithm and allowed alternatives with minimum parameters, rather than a single choice that half the company cannot implement.

Example policy table (minimums, reviewed yearly)
AlgorithmStatusMinimum parameters
Argon2idpreferred19 MiB memory, 2 iterations, 1 lane
bcryptallowedcost 12 (check measured time)
PBKDF2-HMAC-SHA256allowed where FIPS is required600,000 iterations
scryptallowedN = 2^17, r = 8, p = 1
SHA-*, MD5, unsalted anythingforbiddenmust be migrated
The numbers follow widely used public guidance at the time of writing; the policy owner checks them at each review.

3Setting the Cost by Measurement

Parameters copied from a document ignore our hardware and our traffic. Instead we measure. We run the chosen encoder on the same instance type as production and find the parameters that take a target time, for example 100 to 250 milliseconds per hash.

Then we check capacity. Suppose peak traffic is 300 logins per second and one hash takes 200 milliseconds of CPU. That is 60 CPU-seconds of hashing per second, so about 60 cores busy with nothing but password checks at peak, plus headroom for an attack that floods the login form. If that is too expensive, we lower the target time a little rather than skip the measurement, and we protect the login endpoint with rate limits so attackers cannot use our own hashing cost against us.

Java
// Measure on production-like hardware, not on a laptop
var encoder = new Argon2PasswordEncoder(16, 32, 1, 19_456, 2); // salt, hash length, lanes, KiB memory, iterations
long start = System.nanoTime();
for (int i = 0; i < 50; i++) encoder.encode("correct horse battery staple");
System.out.println((System.nanoTime() - start) / 50 / 1_000_000 + " ms per hash"); // e.g. 48 ms per hash

Notice that memory matters for Argon2 too: 19 MiB per hash times 300 concurrent checks is about 5.7 GiB. Memory-hard means hard for us as well, and the policy must say so.

4Making Every Hash Upgradeable

The decision we make today will be wrong in five years, so the policy must require that each stored hash records its algorithm and parameters. Standard formats already do this: bcrypt values contain the cost ($2a$12$), and Argon2 values contain the memory, iterations and lanes ($argon2id$v=19$m=19456,t=2,p=1$...). In Spring applications, DelegatingPasswordEncoder adds the algorithm id in braces.

With that information, upgrading is a login-time task. When a user logs in and their stored value uses an older algorithm or lower parameters than the current policy, the application re-hashes the password with the current settings. In Spring Security this is upgradeEncoding() plus a UserDetailsPasswordService; other stacks have similar needs-rehash checks. The policy should require this behaviour, not just the algorithm.

5Keeping the Policy Current

We give the policy an owner and a review date, yearly or when guidance changes. At each review we re-run the measurement on current hardware, check public guidance, and raise minimums if attackers' hardware has moved faster than ours. A short report per application, showing the share of hashes on current parameters, tells us where upgrades are stuck. Applications whose users rarely log in may need a wrapping step, hashing the old hash with the new function, to move faster than logins allow.

Step throughYearly review of the password policy
  1. Re-measure hash time on current hardwareper algorithm
  2. Check current public guidanceminimum parameters
  3. Below target or guidance?
    YesRaise the minimums and announce a dateNoKeep the parameters
  4. Report share of hashes on current parametersper application
  5. Applications stuck on old formats get a migration plan

5 steps in order. Play them, or step through them one at a time.

6The Bigger Win: Store Fewer Passwords

The best password hash is the one we never store. Every application with its own password table is another place to get the policy wrong and another breach to report. So the long-term direction is to move staff to a central identity provider with single sign-on and customers to a central customer identity service, and to offer passkeys, which replace passwords with public-key credentials. The hashing policy then applies to a handful of systems run by a team that specialises in it, and most applications store no passwords at all.

7Follow-up questions

Why not simply require the highest possible cost?

Because the cost is paid on every legitimate login too. A cost that takes two seconds per hash makes login slow and lets an attacker exhaust our CPUs with a small flood of requests. The policy aims for the slowest setting our capacity and user experience can afford, not the slowest setting possible.

How do we enforce the policy across many teams?

With a shared library or starter per stack that wires the approved encoder and the upgrade-on-login behaviour, a check in security reviews, and a scan that reports the hash formats found in each database. Making the right thing the default works better than auditing after the fact.

What about passwords that are already in an old format?

They follow the same path as any parameter change: upgrade on login, wrap the old hash with the new function for inactive accounts if the risk is high, and force a reset after a deadline. The policy should give each application a date by which old formats must be gone.

8Conclusion

In this answer, we built a company password hashing policy: an adaptive algorithm chosen for support across all stacks, with Argon2id preferred and bcrypt or PBKDF2 allowed where needed; parameters set by measuring on production hardware against peak login capacity; stored formats that record algorithm and parameters so every hash can be upgraded on login; a yearly review with an owner; and a strategy to store fewer passwords through central identity and passkeys.

What to say in the interviewAbout 80 seconds aloud

Open with

I would treat it as a decision with three parts: algorithm, parameters and how both change over time. For the algorithm I would prefer Argon2id because it is memory-hard, but only after checking that every stack we use has a well-maintained library; so the policy names Argon2id as preferred and allows bcrypt, scrypt, or PBKDF2 where FIPS is required, each with minimum parameters.

Then, if they want more

For the parameters I would measure on production hardware, targeting something like 100 to 250 milliseconds per hash, and then check capacity: at 300 logins per second and 200 milliseconds each, hashing alone needs about 60 cores, and Argon2 also needs memory per concurrent check, so login endpoints need rate limits.

The policy must require that each stored hash records its algorithm and parameters, which standard bcrypt and Argon2 formats do, and that applications re-hash on successful login when the stored value is below current policy; in Spring that is DelegatingPasswordEncoder with upgradeEncoding and a UserDetailsPasswordService.

I would give the policy an owner and a yearly review that re-measures and checks current guidance, with reports of how many hashes are still on old parameters. And strategically, I would push applications onto central identity and passkeys, so very few systems store passwords at all.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Security reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Security asks you to pick a password hashing policy for all applications in the company...": https://scrivio-interview-library.netlify.app/spring-boot/authentication/1f6ac38b2e/