Detect spaces in password if user fail to login (#1038)

This commit is contained in:
Benoit Marty 2020-03-04 10:37:31 +01:00
parent 0121eee5b8
commit d6df0e451c
3 changed files with 15 additions and 1 deletions

View file

@ -6,6 +6,7 @@ Features ✨:
Improvements 🙌:
- Add support for `/plain` command (#12)
- Detect spaces in password if user fail to login (#1038)
Bugfix 🐛:
- Fix crash on attachment preview screen (#1088)

View file

@ -209,7 +209,14 @@ class LoginFragment @Inject constructor() : AbstractLoginFragment() {
} else {
// Trick to display the error without text.
loginFieldTil.error = " "
passwordFieldTil.error = errorFormatter.toHumanReadable(state.asyncLoginAction.error)
if (error is Failure.ServerError
&& error.error.code == MatrixError.M_FORBIDDEN
&& error.error.message == "Invalid password"
&& spaceInPassword()) {
passwordFieldTil.error = getString(R.string.auth_invalid_login_param_space_in_password)
} else {
passwordFieldTil.error = errorFormatter.toHumanReadable(error)
}
}
}
// Success is handled by the LoginActivity
@ -226,4 +233,9 @@ class LoginFragment @Inject constructor() : AbstractLoginFragment() {
is Success -> Unit
}
}
/**
* Detect if password ends or starts with spaces
*/
private fun spaceInPassword() = passwordField.text.toString().let { it.trim() != it }
}

View file

@ -29,4 +29,5 @@
<string name="command_description_plain">Sends a message as plain text, without interpreting it as markdown</string>
<!-- END Strings added by Others -->
<string name="auth_invalid_login_param_space_in_password">Incorrect username and/or password. The entered password starts or ends with spaces, please check it.</string>
</resources>