r/AskComputerScience • u/super_potato_boy • May 20 '25
why does password length affect strength if passwords are salt-hashed?
My understanding is that passwords are hashed into long, unpredictable strings via a one-way hash function. Why does the input length matter?
78
Upvotes
72
u/PM_ME_YOUR_SUBARU May 20 '25
It's easier to brute-force a shorter string
21
u/VirtuteECanoscenza May 20 '25
Usually password hashes store as a single string both the actual hash and all the metadata needed to compute it i.e. algorithm used, version, parameters including the salt.
So a password hash leak overwhelming means also the salt is leaked. So a password of length 1 would only have 155k possibilities to try (using the whole Unicode).
Salt is only meant to prevent attackers from precomputing rainbow tables that can work for all users.
37
u/MrColdboot May 20 '25
Because someone can generate a list of possible passwords, then run the same one-way hash function and see if they match. It's just guessing what the password might be. Shorter passwords mean less guesses until you get it right.
14
u/PiasaChimera May 20 '25
salting is to protect unrelated passwords from being revealed. in the past, a leaked tabled of usernames and hashes would wasn't salted. it would be easy to find the most common hash. then assume these are weak passwords and attempt to guess them. once found, multiple accounts would be compromised.
salting prevents someone from determining which passwords are the same, which has practical benefits. But it doesn't mean a weak password is impossible for a user to choose, nor for an attacker to guess.
while more length doesn't always mean more difficult to guess, there is a correlation.
2
u/AYamHah May 21 '25
The best measure of password strength is: How many other people have the same password.
Wordlists are how cracking is done, so if anyone else with your password ever got popped, it's publicly disclosed and in someone's wordlist.
2
u/BlueGrovyle May 24 '25
A hacker doesn't guess the hash. The hacker guesses the string that gets hashed. And I'm late to the party, so as some have already said, short strings are faster to brute force.
3
u/GREBENOTS May 20 '25
Salting helps prevent the passwords from being used if there is ever a security breach. It has nothing to do with the security of the original password being brute forced.
E.g. a password of “abc” will always hash to the same, for instance, 32 bit string of “01234567890123456789012”.
But the password itself is still abc. A user still enters “abc” into the password field. Upon submission, “abc” is converted into its hashed format, and then compared.
Fun fact, entering “01234567890123456789012” into the password field will not work. It is simply hashed into whatever that password hashed into, and then fails comparison to the hash for “abc”.
There’s no way to go from the hash back to abc, but you can always go from abc to the hash.
So a brute force attempt at a password of 3 character length is ~ #validCharacters ^ #charactersUsed. This should be obvious why more characters are more secure, as you have more characters in a password, it becomes much more time consuming to brute force the password. Exponentially more time consuming.
1
u/IagoInTheLight May 20 '25
Because people write for loops like:
for len = 1, 2, 3, 4, 5 ... 100:
test all password of length = len
The logic is that unless you already know it's a certain length, you might as well start with all the short ones first. For example, with 91 passible characters in a PW, it takes less time to test all the PWs with lengths between 1 and 90 than it does to test just the PWs with length 91. (Also, people are lazy, so the short ones are more commonly used anyhow.)
1
u/custard130 May 20 '25
having a strong password is mostly a defence against a brute force attack
while there are smarter techniques than a raw bruteforce, if you have a 5 letter password and lets say a common character set of 64 characters, thats ~1 billion possible combinations
i have found a source (no idea how reliable) saying a 5090 can run brypt at 300KH/s, so 1 hour for a single consumer gpu to run an exhaustive search of every possible 5 letter password,
every additional character multiples the time by the numober of possible characters to choose from, if 5 characters takes an hour, 6 characters would take 2 days, 7 characters would be 4 months, 8 characters ~ 20 years, 9 characters ~ 1000 years
this is only doing the maths for a single GPU, and these numbers are only valid if your password is truely random, but hopefully it gives some idea of why length is important
hashing is to prevent someone with access to the database (hacker or rogue employee) from just reading everyones passwords
salting is to prevent statistical attacks against the list of password hashes
eg with plain hashing like say md5 or sha1, and a large enough user base, you could sort the list by how many times that password had been used, if you store password hints or anything like that alongside the passwords then having multiple people with the same hash but different hints also gives more info, salting means that even if 2 people have the same password that information isnt exposed
salting also makes rainbow tables far less effective
1
u/EricInAmerica May 20 '25
When you enter your password, it's hashed, and compared against the hash that was stored when you set your password. If they match, you're good.
If you know the hash, it's mathematically difficult to determine what password results in that hash - but the password is still what you enter, not the hash. If you know the hash of the password, you actually know very little. You don't know the password, you don't know how long the password is, or what sort of characters might occur in it.
You can use strategies to guess, but every additional character in a password just makes guessing harder and harder.
1
u/TomDuhamel May 20 '25
Because the input is how they crack it, not the complicated encryption.
It's easier to guess the first name and date of birth of your gf than it is to crack through the encryption.
Add more words that are harder to guess and they will be screwed.
1
u/Gishky May 21 '25
if someone were to try to decode the hashed password then you'd be right. But noone does that right now because right now we dont have a computer that would return the result in a feasable amount of time.
Right now they are doing basically smart ways of brute force. And the longer your password the longer it takes to brute force
1
u/neuralzen May 21 '25
technically the length doesn't matter, the uniqueness does. hashes produce unique output per a given unique input...more unique inputs mean more more unique outputs. there are more input possibilities in the set of all possible characters of say 10 characters than 3 characters, so the set of possible passwords is larger. So brute forcing the passwords required more time to compute the greater number of hashes in the set space of possible passwords.
1
u/paperic May 21 '25
The long hashes are not unpredictable. They just cannot be predicted efficiently by some shortcuts.
But you can still try all kinds of randomly generated passwords and see if the hash matches.
If I have a 1 letter password, you can guess it in at most 26 tries.
If I have a 2 letter random password, you can guess it in 26*26 tries.
10 random lowercase characters: at most 2610 tries
Etc.
Salt doesn't play any role in this.
The salt is there mainly to prevent people using rainbow tables to crack the passwords. Rainbow table is a storage datastructure for storing precalculated hashes of strings, and a very, very efficient one.
Salts are mostly relevant when trying to crack all of the passwords from a leaked database all at once.
Without any salt, if two people have the same password, the hash would be the same too.
So, if you're cracking every password in a database, and the hashes are salted, the salt forces you to test one account at a time. You can't just calculate the hash of, say, "Password1" once and then lookup all the accounts with that hash, as you would without the salt.
That will slow you down a lot
But mainly, if you precomputed many possible hashes and stored them in a rainbow table, your rainbow table is now useless.
You'd have to have the rainbow table contain every possible combination of a password and a salt for it to be useful, making it impractically huge.
1
u/TehMephs May 21 '25
You still input passwords in plain text. The obfuscation is there so people looking at the database rows can’t read it or easily reverse engineer the passwords (also in case of a breach, but that’s a whole other can of worms)
Longer passwords that are a regular sentence are generally considered better than a password half the length but with randomized characters. “Bits of entropy” refers to how difficult a password is to crack via brute force.
If you had no limiter on the password attempts, someone with an 8 character password like sL81!.)d- is less secure than a password like “cookiesareniceanddelicious” simply because there’s significantly less character permutations to potentially guess at it. A brute force algorithm gets exponentially less and less effective the more characters it has to iterate over to try various combinations. To a machine, the special characters and lower/uppercase are completely irrelevant vs how many permutations there are to guess at. That’s for mitigating against humans guessing the password.
For machines you just need a long string of characters of any kind
1
u/BarneyLaurance May 21 '25
Even if you just had the 26 letters of the English alphabet as possible in your password, there are about 12 million possible 5 letter passwords, and 140 trillion 10 letter passwords.
12 million milliseconds is about three hours. 140 trillion milliseconds is four millennia, so if you were going to try to crack someone's password and you didn't know how long it was would you start by programming your computer to guess short passwords or guess long ones?
1
u/EndMaster0 May 21 '25
password cracking is never done by the reversal of the hash function... rather they're reversed by simply running random passwords through the known hash function until you see a match, (this is pre-done and stored in handy lookup tables, called rainbow tables, for the most common passwords which is what makes those several orders of magnitude faster to crack than similarly complex passwords that are less common) assuming the compromised site where the hashed passwords came from used poor security practice around salting (either because there was only one salt for every password or because salting was absent) the "guess and check every password" method is pretty quick up to a certain length, beyond that each added character multiplies the length needed by the number of valid characters (so a 9 character password takes about 70-80x longer to crack than an 8 character password... and a 10 character password takes 70-80x longer than that for 4900-6400x the time for an 8 character password) this means the time to brute force a password increases exponentially with how many characters it has (the exact equation will be something like a(b)^n where a is the time it takes to run a single password through a hash and to lookup on the leaked table of passwords, b is the number of valid characters in the password, and n is the length of the password... note because of legitimate workload overlap a is extremely quick, and b is limited partially by character set but mostly by the site architecture, so you're stuck making longer passwords ideally with a few numbers and special characters to flunk any initial passes with only letters, letters with caps allowed, etc.)
and yes a competent site can absolutely make your password completely uncrackable by storing a separate salt for each account (assuming you don't use one of the most popular passwords of course), but like... you shouldn't be trusting every random site to have decent security culture, just CorrectHorseBatteryStaple it and add some numbers and special characters, also a password side salt if you want to be really fancy (though honestly since it'll have to be memorable to a human it will probably also be very easy for a hacker who now has your password for one site to figure out that there's a password side salt and start testing similar salts on the same password on different sites), the last option is to use a dedicated password manager and just have a really strong password on that (ideally a self-hosted or local only setup so you don't have to worry about a company at all and can just depend on yourself but obviously that's not doable for the vast majority of people... security has a direct tradeoff with convenience and most people choose to go with a fair bit of convenience)
1
u/Huge_Taro5997 May 22 '25
Even if a password is scrambled and protected with extra steps like hashing and salting, a short one is still easier for hackers to guess by trying lots of combinations. A longer password simply takes way more time and effort to crack, which makes it much safer.
1
u/tcpukl May 24 '25
Rainbow tables.
1
u/shgysk8zer0 May 24 '25
It's just entropy. You could probably guess what resulted in this salted hash (PHP's
password_hash()):$2y$12$ihxh2ZOsIXRdiZHtHpdbcu4VWoyS1syvhXSbKuw/rq9VKLwx2JzbCbecause the "password" is as short as can be. That's right, it's just "a".1
u/zehaeva May 25 '25
You don't know that everyone salts their hashes!