| Goal | This query checks whether stored bcrypt password hashes use a cost factor (work factor) lower than 12. It inspects text-based columns in base tables whose names suggest password storage, parses the cost parameter from sample bcrypt hashes ($2a$, $2b$, $2x$, or $2y$), and flags entries where the numeric cost is less than 12. Because the bcrypt cost factor scales exponentially (2cost iterations), an insufficiently low work factor drastically reduces the computational effort required for attackers to perform offline brute-force cracking if the database or its backups are compromised. |
|---|---|
| Type | Problem detection Each row in the result could represent a flaw in the design |
| Reliability | Medium Medium number of false-positive results |
| License | MIT (opens in new tab) |
| Data Source | INFORMATION_SCHEMA+system catalog |
| SQL Query |
|
Fixing Suggestion
bcrypt cost factor to at least 12: - Explicitly set the cost factor: Update your application or database hashing logic to specify a cost factor of
12or higher (for example, when using PostgreSQL'spgcryptoextension, pass the parameter explicitly:crypt(password, gen_salt('bf', 12))). - Benchmark login performance: Test the updated cost factor on your target production hardware to ensure an optimal balance between brute-force resistance and acceptable user login latency.
- Rehash transparently on login: Because existing hashes cannot be upgraded without the user's plaintext password, update your authentication workflow to detect hashes with a cost factor below 12 during successful logins and automatically re-hash and save them with the stronger setting.
SQL statement to clean up temporary or helper database objects created for or by this query.
DROP FUNCTION IF EXISTS f_check_password();
Collections
This query belongs to the following collections:
Find problems automatically
Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
| Name | Description |
|---|---|
| Find problems automatically | Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not . |
Categories
This query is classified under the following categories:
Data at the database logical level
Queries of this category provide information about data in base tables.
Result quality depends on names
Queries of this category use names (for instance, column names) to try to guess the meaning of a database object. Thus, the goodness of names determines the number of false positive and false negative results.
Security
Queries of this category provide information about the security measures.
| Name | Description |
|---|---|
| Data at the database logical level | Queries of this category provide information about data in base tables. |
| Result quality depends on names | Queries of this category use names (for instance, column names) to try to guess the meaning of a database object. Thus, the goodness of names determines the number of false positive and false negative results. |
| Security | Queries of this category provide information about the security measures. |