How to update passwords to secure their storage with Argon2? (2024)

How to update passwords to secure their storage with Argon2? (1)

In a previous article, we saw why it was important to store passwords in a database with robust hash functions such as Bcrypt and Argon2. This helps to render brute force or dictionary attacks completely ineffective.

However, a problem is regularly noted on already existing applications: how to use the latest recommendations on password storage on an existing database?

How to securely store passwords?

Before getting to the heart of the matter, a few details on the OWASP recommendations on password storage:

  • Use Argon2id with a minimum configuration of 19 MiB of memory, a number of iterations of 2, and 1 degree of parallelism.
  • If Argon2id is not available, use Scrypt with a minimum CPU/memory cost setting of (2^17), a minimum block size of 8 (1024 bytes) and a parallelism setting of 1.
  • For older systems using Bcrypt, use a work factor of 10 or more and a password limit of 72 bytes.
  • If FIPS-140 compliance is required, use PBKDF2 with a work factor of 600,000 or more and an internal hash function of HMAC-SHA-256.
  • Use a pepper to provide additional defense in depth (although on its own it does not provide any additional security features).

In the following, we will show how to update passwords with Argon2id. To do this, we will start from 2 common cases:

  • Passwords are stored in clear text or with an encryption algorithm.
  • Passwords are stored with an unsuitable hash (md5, sha1, sha2, sha3…).

However we will not implement a pepper. In case you want to add a pepper, just hash the pepper + password. As a reminder, the pepper is identical for all users.

Moreover, we will provide PHP code as an example, but the algorithms can be applied to other languages.

Passwords are stored in clear text or with an encryption algorithm

Updating passwords in database with Argon2id

First of all, it is important to remember that storing passwords in clear, readable text is forbidden in certain countries such as France. It is therefore imperative to change your password management.

And if you are starting from scratch (a case we will not see in this article), you can consult the following content which details: How to Securely Store Passwords in Database?

Let us now return to our subject.

In the case presented here, since the passwords are easily identifiable (because they are stored in clear text), it is only required to update the passwords with the following algorithm:

How to update passwords to secure their storage with Argon2? (2)

This will result in the user table being transformed from:

IDNamePassword
1adminazerty
2totomatrix
3billyyep59f$4txwrr
4tatamatrix
5titifreepass
6attackertesPwndPassword

To:

IDNamePassword
1admin$argon2id$v=19$m=65536,t=4,p=1$UjYzcS42QmhmLjFsa3lrYQ$7t8mfl
Th2JhcVqSTdQ0GwtLtMh6plWECubPEH8NjEUM
2toto$argon2id$v=19$m=65536,t=4,p=1$SURlcDNVUDZFWEVlQy5UYg$mv
m0Iohc9nd/KOLP5kAw6/WB+PAK0Nt6QGPTsdQa8aw
3billy$argon2id$v=19$m=65536,t=4,p=1$WTlMMDJDeUVMeDNONXRDaQ$u
ccT7LUNmJcj8+ZLqtT+U7m+IJePgCuvv8BxCzRYKG4
4tata$argon2id$v=19$m=65536,t=4,p=1$c00udFlHMm1LMXhwcDBjVg$NR0I
QiLqC0dMSgYHbtEhcAGdrFqhdI4YoOTjtMW1zZA
5titi$argon2id$v=19$m=65536,t=4,p=1$U1Y2dm44cXlMWHp0SkFhVg$lYj9k
Lfx6zUNOTDUXHDhpEFyBdSJXDv9qjxA0+4oEYw
6attacker$argon2id$v=19$m=65536,t=4,p=1$NmFqZVhOaTRsN2t4L3lWRw$UJbZ
AJcm7ujhLv/Y/DcyMDqD42ME95l+Cd5Kh2XJ2G0

It should be noted that the application does not impose a strong password policy, which is essential to avoid risks of compromise. It is therefore strongly recommended to impose the use of strong passwords when creating them.

For more information, we refer you to our article: How to secure authentication, session management and access control systems of your web applications?

Thanks to the password_get_info function, only non-Argon2 passwords are transformed. This allows the script to be run several times without the risk of hashing the passwords several times.

Furthermore, it is important to make a backup of the database to avoid the risk of corrupting users in the event of migration problems.

NB: if an encryption algorithm is used, the clear passwords must be hashed directly, not the encrypted data.

Checking the validity of user passwords

To confirm the presence or not of a user, it is simply necessary to compare the password and the hash with the password_verify function (or equivalent in other languages).

How to update passwords to secure their storage with Argon2? (3)

Even if the operation is invisible to the user, it is still strongly recommended to encourage users to change their password after this modification.

The operation will be as follows:

We add a column to the user table, for example isUpdatePassword which is false by default:

sqlite> ALTER TABLE USERS ADD isUpdatePassword bool default false;sqlite> select * from USERS;id|name|password|isUpdatePassword1|admin|$argon2id$v=19$m=65536,t=4,p=1$UjYzcS42QmhmLjFsa3lrYQ$7t8mflTh2JhcVqSTdQ0GwtLtMh6plWECubPEH8NjEUM|02|toto|$argon2id$v=19$m=65536,t=4,p=1$SURlcDNVUDZFWEVlQy5UYg$mvm0Iohc9nd/KOLP5kAw6/WB+PAK0Nt6QGPTsdQa8aw|03|billy|$argon2id$v=19$m=65536,t=4,p=1$WTlMMDJDeUVMeDNONXRDaQ$uccT7LUNmJcj8+ZLqtT+U7m+IJePgCuvv8BxCzRYKG4|04|tata|$argon2id$v=19$m=65536,t=4,p=1$c00udFlHMm1LMXhwcDBjVg$NR0IQiLqC0dMSgYHbtEhcAGdrFqhdI4YoOTjtMW1zZA|05|titi|$argon2id$v=19$m=65536,t=4,p=1$U1Y2dm44cXlMWHp0SkFhVg$lYj9kLfx6zUNOTDUXHDhpEFyBdSJXDv9qjxA0+4oEYw|06|attacker|$argon2id$v=19$m=65536,t=4,p=1$NmFqZVhOaTRsN2t4L3lWRw$UJbZAJcm7ujhLv/Y/DcyMDqD42ME95l+Cd5Kh2XJ2G0|0

Then in the login form, the user will be redirected to a password reset form if their password has not been changed, otherwise they can access the platform.

How to update passwords to secure their storage with Argon2? (4)

Here we save the user’s login or name in the session after validating the connection.

Finally, the code to process the password change form will be as follows:

How to update passwords to secure their storage with Argon2? (5)

Note: Here we only check that the old password is different from the new one. Ideally, we should also check that the password follows a strong policy.

Passwords are stored with an unsuitable hash (md5, sha1, sha2, sha3…)

Migrating hash to Argon2id

In this case, the data migration is more complex, because the passwords are not identifiable. Here, what we advise is to do Argon2id directly on the hash stored in the database.

For our example, we place ourselves in a case where the hash md5 is used, with salt and pepper to be in the most complex case possible.

The passwords are therefore stored in the database in this way: md5 (salt + password + pepper).

The connection will thus have this form:

How to update passwords to secure their storage with Argon2? (6)

The conversion code will be the same as the previous example. Indeed, it is directly the md5 hash that we want to encode, a value that is already present in the database (password column).

How to update passwords to secure their storage with Argon2? (7)

The login form will be more complex, however, as we have several conditions to validate:

  • When the user logs in for the first time, ask for a new password and store only the argon2id of that password
  • Have to handle 2 cases in the login form:
    • If the column isUpdatePassword is false, then the user has not changed their password and the hash will be: argon2id (md5(salt + password + pepper).
    • If the column isUpdatePassword is false, then the user has changed their password and the hash will be: argon2id (password + pepper).
How to update passwords to secure their storage with Argon2? (8)

And the reset form will be as follows:

How to update passwords to secure their storage with Argon2? (9)

If you use a suitable hash

Algorithms considered reliable for storing passwords have a positive point: they can adapt with time and the evolution of hardware by increasing their cost. It can therefore be relevant to anticipate the evolution of algorithms in your login form.

In PHP you can use the password_needs_rehash function.

Author : Thomas DELFINO – Pentester @Vaadata

How to update passwords to secure their storage with Argon2? (2024)
Top Articles
Create a Travel Budget Vacation Worksheet
Financial and Managerial Accounting by Sue Haka, Jan Williams, Mark S. Bettner and Joseph V. Carcello (2009, Hardcover) for sale online | eBay
Hotels Near 6491 Peachtree Industrial Blvd
My Arkansas Copa
Overton Funeral Home Waterloo Iowa
Hotels
News - Rachel Stevens at RachelStevens.com
Collision Masters Fairbanks
Martha's Vineyard Ferry Schedules 2024
Wells Fargo Careers Log In
Polyhaven Hdri
Acts 16 Nkjv
Aiken County government, school officials promote penny tax in North Augusta
David Packouz Girlfriend
Publix 147 Coral Way
When Is the Best Time To Buy an RV?
The Weather Channel Facebook
83600 Block Of 11Th Street East Palmdale Ca
Mens Standard 7 Inch Printed Chappy Swim Trunks, Sardines Peachy
How do you like playing as an antagonist? - Goonstation Forums
Void Touched Curio
Clarksburg Wv Craigslist Personals
Nene25 Sports
Craigslist Farm And Garden Tallahassee Florida
TBM 910 | Turboprop Aircraft - DAHER TBM 960, TBM 910
Pokemon Unbound Shiny Stone Location
Noaa Duluth Mn
John Philip Sousa Foundation
Mchoul Funeral Home Of Fishkill Inc. Services
Till The End Of The Moon Ep 13 Eng Sub
Parent Management Training (PMT) Worksheet | HappierTHERAPY
Kelley Fliehler Wikipedia
What Is The Lineup For Nascar Race Today
Average weekly earnings in Great Britain
24 slang words teens and Gen Zers are using in 2020, and what they really mean
Poe Flameblast
Td Ameritrade Learning Center
Blackwolf Run Pro Shop
Henry Ford’s Greatest Achievements and Inventions - World History Edu
Questions answered? Ducks say so in rivalry rout
Stewartville Star Obituaries
'Guys, you're just gonna have to deal with it': Ja Rule on women dominating modern rap, the lyrics he's 'ashamed' of, Ashanti, and his long-awaited comeback
Alston – Travel guide at Wikivoyage
Www Craigslist Com Atlanta Ga
Dickdrainersx Jessica Marie
Marcal Paper Products - Nassau Paper Company Ltd. -
Ratchet And Clank Tools Of Destruction Rpcs3 Freeze
Steam Input Per Game Setting
The top 10 takeaways from the Harris-Trump presidential debate
Greg Steube Height
Home | General Store and Gas Station | Cressman's General Store | California
Www Extramovies Com
Latest Posts
Article information

Author: Msgr. Benton Quitzon

Last Updated:

Views: 6292

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Msgr. Benton Quitzon

Birthday: 2001-08-13

Address: 96487 Kris Cliff, Teresiafurt, WI 95201

Phone: +9418513585781

Job: Senior Designer

Hobby: Calligraphy, Rowing, Vacation, Geocaching, Web surfing, Electronics, Electronics

Introduction: My name is Msgr. Benton Quitzon, I am a comfortable, charming, thankful, happy, adventurous, handsome, precious person who loves writing and wants to share my knowledge and understanding with you.