I believe the answers are good, but @Stormwind’s response to "a generic error message" left me a little puzzled.
Today in systems like Google and Microsoft is different from the past, now first ask for the login and only if it is correct ask for the password.
I believe this is because the password is not so relevant. There is already authentication in two (or more) factors. In the past, only the knowledge of the password already gave access to the account. Nowadays this does not apply, now you need more than just the password.
Specifically, Google even allows the use of FIDO U2F, which requires a physical key, USB, which contains an ECDSA key, in which it signs the "challenge".
Anyway, even if the attacker knows the e-mail and the password, he’ll still have a job. Therefore, I believe that it has become irrelevant the attacker know only the email and as has been said, have started to inform the user what is wrong, improving his experience.
Does this happen to protect data? Or could we say that it is because it is easier to do so?
Reporting two identical texts does not provide any security, you need to perform exactly the same thing. Otherwise, you can inform the attacker that the user exists or not, in other ways.
Consider this code, INSECURE:
func login(w http.ResponseWriter, r *http.Request) {
var hashedPassword string
var username = r.PostFormValue("username")
var password = r.PostFormValue("password")
if username == "" || password == "" {
fmt.Fprint(w, "Você precisa enviar os dados")
return
}
err := db.QueryRow("SELECT `senha` FROM login WHERE usuario = ? LIMIT 1", username).Scan(&hashedPassword)
if err != nil {
fmt.Fprint(w, "Senha ou usuário incorreto")
return
}
if err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)); err != nil {
fmt.Fprint(w, "Senha ou usuário incorreto")
return
}
fmt.Fprint(w, "Conectado com sucesso")
}
The above code will always enter "Password or incorrect user" if you miss one of the things. You can say that the above code meets what @Stormwind says:
If you use a generic error message, you are "increasing security" since the attacker will not know if you have taken valid and existing names on your system [...]
But.... No. That doesn’t add any security. An attacker can still get the original information, note that the processing time is different:
User "Domain name":
curl -d "username=QueNaoExiste&password=a" http://127.0.0.1:8888/login -w " "%{time_total}
Incorrect password or user 0,000
User "Queexiste":
curl -d "username=QueExiste&password=a" http://127.0.0.1:8888/login -w " "%{time_total}
Incorrect password or user 2,156
"Queexiste" user with the right password:
curl -d "username=QueExiste&password=umasenhamuitolouca" http://127.0.0.1:8888/login -w " "%{time_total}
Successfully connected 2,157
A non-existent user does not do Bcrypt, so the result is faster than the one that does the comparison. The %{time_total}
informs the total time spent until the request is completed. It is not enough that the messages are the same, you have to make it impossible to extract the true information in other ways. In this specific case you should protect yourself from timming-Attack.
This is just ONE of the thousands of methods that can be used, even where "the message is equal". In another real case, there is a website (I won’t mention the name here) that when logging in, the customer receives a id
. But when you try to log in to a non-existent account, id
is temporary. Just wait awhile and try a new login. If the new id
is different from the old is because it does not exist, if it remains the same.... You hit the user.
An equal message, by me, does not guarantee any security. There are more things to be done than just "an equal message".
Briefly speaking: this is to avoid giving hints to a possible attacker who hit the user; at length: not doing user verification and password separator implies a single access to the bank, which implies performance gain by not expecting communication latency. Not to mention that consulting only one or both has basically the same weight. Expecting someone to provide a more complete and reasoned answer of the subject
– Jefferson Quesado
Well, I can’t tell why Google changed the password validation design, but these were the reasons I knew
– Jefferson Quesado
This basically depends on the volume of users in the application. If you have a small system with a hundred users, the correct user information is precious. In the case of google and MS, the vast majority of the things you "kick" is a valid user, so it is irrelevant to protect this part of the credentials, which consequently allows you to rethink the mechanism. On the usability of the UI, they are equivalent solutions. The "effort" to switch fields on the same screen is equivalent to entering the username to jump to the next screen, so the choice of steps will be made by other criteria
– Bacco
Curiosity: as always, Google implodes things "more or less". I’ve noticed a lot of places where you have the time to hit the user, but the avatar doesn’t show up (which totally ruins the advantage of you evaluating whether it’s in the correct form, not a fake one). At first I thought it could really be a Mitm attack, but I confirmed in completely different places and equipment and with more than one account (from different people, including).
– Bacco