fix: incorrect error messsage for invalid login credentials (#10117)

* fir ErrorCode enum

* update incorrect credentails message
pull/10138/head
Purushottam Khedre 2023-07-13 17:39:19 +05:30 committed by GitHub
parent c1a9f4b656
commit 352a9e2fec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 9 deletions

View File

@ -69,7 +69,7 @@ export default function Login({
const errorMessages: { [key: string]: string } = {
// [ErrorCode.SecondFactorRequired]: t("2fa_enabled_instructions"),
// Don't leak information about whether an email is registered or not
[ErrorCode.IncorrectUsernamePassword]: t("incorrect_username_password"),
[ErrorCode.IncorrectEmailPassword]: t("incorrect_email_password"),
[ErrorCode.IncorrectTwoFactorCode]: `${t("incorrect_2fa_code")} ${t("please_try_again")}`,
[ErrorCode.InternalServerError]: `${t("something_went_wrong")} ${t("please_try_again_and_contact_us")}`,
[ErrorCode.ThirdPartyIdentityProviderEnabled]: t("account_created_with_identity_provider"),

View File

@ -58,7 +58,7 @@ test.describe("Login and logout tests", () => {
test.describe("Login flow validations", async () => {
test("Should warn when user does not exist", async ({ page }) => {
const alertMessage = (await localize("en"))("incorrect_username_password");
const alertMessage = (await localize("en"))("incorrect_email_password");
// Login with a non-existent user
const never = "never";
@ -69,7 +69,7 @@ test.describe("Login and logout tests", () => {
});
test("Should warn when password is incorrect", async ({ page, users }) => {
const alertMessage = (await localize("en"))("incorrect_username_password");
const alertMessage = (await localize("en"))("incorrect_email_password");
// by default password===username with the users fixture
const pro = await users.create({ username: "pro" });

View File

@ -477,7 +477,7 @@
"max_limit_allowed_hint": "Must be {{limit}} or fewer characters long",
"invalid_password_hint": "The password must be a minimum of {{passwordLength}} characters long containing at least one number and have a mixture of uppercase and lowercase letters",
"incorrect_password": "Password is incorrect.",
"incorrect_username_password": "Username or password is incorrect.",
"incorrect_email_password": "Email or password is incorrect.",
"use_setting": "Use setting",
"am_pm": "am/pm",
"time_options": "Time options",

View File

@ -1,5 +1,5 @@
export enum ErrorCode {
IncorrectUsernamePassword = "incorrect-username-password",
IncorrectEmailPassword = "incorrect-email-password",
UserNotFound = "user-not-found",
IncorrectPassword = "incorrect-password",
UserMissingPassword = "missing-password",

View File

@ -100,7 +100,7 @@ const providers: Provider[] = [
// Don't leak information about it being username or password that is invalid
if (!user) {
throw new Error(ErrorCode.IncorrectUsernamePassword);
throw new Error(ErrorCode.IncorrectEmailPassword);
}
await checkRateLimitAndThrowError({
@ -112,16 +112,16 @@ const providers: Provider[] = [
}
if (!user.password && user.identityProvider !== IdentityProvider.CAL && !credentials.totpCode) {
throw new Error(ErrorCode.IncorrectUsernamePassword);
throw new Error(ErrorCode.IncorrectEmailPassword);
}
if (user.password || !credentials.totpCode) {
if (!user.password) {
throw new Error(ErrorCode.IncorrectUsernamePassword);
throw new Error(ErrorCode.IncorrectEmailPassword);
}
const isCorrectPassword = await verifyPassword(credentials.password, user.password);
if (!isCorrectPassword) {
throw new Error(ErrorCode.IncorrectUsernamePassword);
throw new Error(ErrorCode.IncorrectEmailPassword);
}
}