I will not hide that the title of this article is a bit provocative, maybe even clickbait. But the full title, "A few words about password hashing, or why you should not give out your password when your administrator or support team asks for it", would not only be unattractive, it simply would not fit in the "columns" of a blog. On the other hand, it would describe exactly what today's text is about and announce a certain public message. Most of us do know that you must not give your password to a consultant or even a member of the technical team, and most of us can guess why (and if not, the reason is the risk of losing your account). But not everyone knows why those consultants can ask us for it at all, and in good faith. Or why administrators cannot recover that information from the service's database themselves.

How are passwords stored in IT systems?

To answer that question, we need to know how passwords are saved in a database, assuming, of course, that the service authenticates users by asking for exactly this kind of "secret". As you probably expect, they are not stored in plain form, that is, as so-called plain text. Of course, that would be the simplest way to store data and the fastest when checking the password a user has typed in, but it does not justify the danger that arises when an unauthorized person gets into the database. The login data would then be visible at a glance.

That is why user passwords saved in a database must be encoded, and here we have a reversible and an irreversible approach. The first one means that every password is transformed by an algorithm that turns one string of characters into another in a way that can be undone later. An example is the famous Caesar cipher, which shifts every character by a set number of positions. Following this trail, if you know the value of the shift, you can reverse the process and learn the original message. On the one hand, this is better than plain text, because the passwords stored in the system really are unreadable at first glance. On the other hand, this protection is very weak, because an attacker will look in the code for the way passwords are handled, and if they find it, they can do anything. That is why reversible encoding is used only when it is truly necessary, which is perhaps 0.01% of all situations.

Irreversible encryption is much better, using so-called hash functions. They work by assigning a short text value to a group of texts. Algorithms like these are useful for indexing data and speeding up searches, but what interests us most is their use in security. One of the simplest hash functions is MD5, which creates a hash made of hexadecimal digits. For example, for the password TajneHaslo123 ("SecretPassword123") this method generates the hash d51472b37f8b58be359ac086c639a7da. What matters is that although an algorithm stands behind it, this code looks random. So random that for a similar password, TajneHaslo124, the hash is c4eaabcaea5623eceda71955d42943a6, completely different from the one for the previous input. What is more, there may be another password that "by accident" gets an identical hash, which means that trying to decipher an incomprehensible string gives the attacker nothing. Rest assured, though: the chances of hitting an identical hash with two different inputs are quite small.

Still, MD5 is a rather weak algorithm for hashing passwords. It is far more useful for comparing information, where we care about, say, uniquely identifying objects and searching for them. Cracking hashes stored with MD5 is so easy for today's computers that keeping credentials in this form is very dangerous and not recommended. There are much better methods such as SHA3 or the very popular bcrypt. With the first one (specifically SHA3-256), our password TajneHaslo123 gets this hash:

1da9221b1fbe5a91e90ccd84ff994823c7c4a9d235044a504b5eb1936b0283aa

and with the second one:

$2a$13$qxKekEVlvm4ugIbxLK/Jf.JHdUmdHmyZbakTPvER0XokIOmhEG7Rm

And this is not the only possible result, because the method has many variants and because of the "salt", an additional masking ingredient.

What these techniques have in common is that they not only store the user's password in an unreadable form, but also that no algorithm exists to turn it back into the original, especially since the hash is "cut off" at some point. This applies not only to a person with a "calculator" and knowledge of how a given method works, but also to a computer. So the login process looks like this: whatever the user types when entering the system is hashed, and then that hash is compared with the one stored in the database. If they match, the user is logged in. Keep in mind that the comparison does not mean complete equality, and depending on the method it can look a bit different.

So how can an attacker get a password if they cannot recover it from the hash? They do not even try. Instead, they can:

  • try different passwords from a possible set of secrets and hope to hit the right one eventually (so-called brute force),
  • use so-called rainbow tables, which save computing power and time and exploit the repetition of hashes,
  • try to gain access to the victim's email and change the password in the service,
  • use a social engineering attack, getting the victim to hand over the password voluntarily.

The topic is very broad (especially when it comes to social engineering), but it is not the topic of this article.

Why would someone want our password?

Of course, the basic reason that comes to everyone's mind (rightly so) is a break-in attempt. The world has seen many "attacks" in which a person posing as a consultant convinced the victim to hand over access to a service easily. That is why you should practically never give your account password to a stranger (or even to someone you know). Now it is time to explain why a real consultant or support employee often does not need such data (we are more likely to be asked over the phone for a "security code" to continue the conversation with the help desk), or conversely, when they may need it.

If we report a problem with a system to someone or need something from the support team, I can assure you that the specialist on the other side, depending on their permission level and tools, can find your data even without having the password. This comes of course from access to the database or special admin panels that make it easier to find and display certain information, for authorized people only. When they talk about users, administrators and developers usually work with database identifiers, email addresses or other unique data. With full discretion and data protection, of course, but still without access to authentication data.

Even if a developer or administrator stood on their head, they would not see user passwords in clear form. The reason is the hashing discussed earlier and the fact that such a hash cannot be translated back into the original code. The only place where you can theoretically see the submitted data is the preview of requests sent in the browser (right after pressing "Log in" and entering your data) or the server logs. But in the first case this route is (or at least should be) protected by the HTTPS protocol, and in the second, such information should be excluded from the server logs. All this also explains why the "remind me my password" option does not actually remind you of the password. Instead, it sends a newly generated temporary code or takes you to a password change form with a suitable token (which also protects against malicious attackers). If a service ever answers the "remind me my password" option by sending you a password that resembles yours, I strongly recommend you stop using that service, because there is a high chance your credentials are in danger.

That does not mean there is no situation in which the service staff do not need your password. Some reports cannot be reproduced in any way other than by logging in to the given account and seeing what the user sees. In the past, a "Log in as..." button available to the administrator was implemented for such situations, letting them enter the person's account automatically. This solution raises doubts under GDPR, though, and it also requires a particular way of handling the authentication process, which in turn is possible only with a particular application structure. So most often the procedure in such situations is this: after getting the user's consent (absolutely!), the service staff change the password to one known only to them and then ask the user to set it again, or they restore the previous hash. Still without knowing the original password. Of course, there is always the option of using TeamViewer or RustDesk to watch live what the user sees on the screen, but then the person handing over control must be absolutely sure they are giving it to the right person.

Is there an alternative to passwords?

Yes, there are services where passwords are not needed or are not the only form of login. Examples are one-time passwords or tokens, which are generated for a short time and sent by email or SMS. Two-factor authentication (2FA) works in a similar way, and it is always worth turning on in services that matter to us. Another way is biometrics, meaning the use of a fingerprint, a face scan or an iris scan. These solutions, although already in use, raise some doubts about privacy and about access to our personal data or the use of our image. Finally, there is also the option of logging in with SSH keys, but it is used rather in specific services and by more technical people.

Summary

As you can see, a password leaking from a database does not have to mean that our credentials are available to criminals, but that does not mean you should not stay alert either. If someone wants to help us with a problem in a service, they will almost never need a password for it, at most goodwill and cooperation from both sides. So let us adopt the rule that we never reveal our passwords, unless it is absolutely necessary and concerns someone close to us.

At the same time, you should not be afraid of the password reminder option, and I can give an example from our own backyard. When we changed the hashing library in Feedybacky, because of a software update on the server, users had to set their passwords again. We could not do it automatically because... we do not know those passwords and never will. So you can feel safe.

Best regards and thank you, Jakub Rojek.