diff --git a/keyserver/src/responders/user-responders.js b/keyserver/src/responders/user-responders.js --- a/keyserver/src/responders/user-responders.js +++ b/keyserver/src/responders/user-responders.js @@ -4,6 +4,7 @@ import t from 'tcomb'; import bcrypt from 'twin-bcrypt'; +import { hasMinCodeVersion } from 'lib/shared/version-utils'; import type { ResetPasswordRequest, LogOutResponse, @@ -227,7 +228,11 @@ } const userRow = userResult[0]; if (!userRow.hash || !bcrypt.compareSync(request.password, userRow.hash)) { - throw new ServerError('invalid_credentials'); + if (hasMinCodeVersion(viewer.platformDetails, 99999)) { + throw new ServerError('invalid_parameters'); + } else { + throw new ServerError('invalid_credentials'); + } } const id = userRow.id.toString(); diff --git a/native/account/log-in-panel.react.js b/native/account/log-in-panel.react.js --- a/native/account/log-in-panel.react.js +++ b/native/account/log-in-panel.react.js @@ -237,16 +237,6 @@ ); }; - onUsernameAlertAcknowledged: () => void = () => { - this.props.setActiveAlert(false); - this.props.logInState.setState( - { - usernameInputText: '', - }, - this.focusUsernameInput, - ); - }; - async logInAction(extraInfo: LogInExtraInfo): Promise { try { const result = await this.props.logIn({ @@ -262,18 +252,11 @@ }); return result; } catch (e) { - if (e.message === 'invalid_parameters') { - Alert.alert( - 'Invalid username', - 'User doesn’t exist', - [{ text: 'OK', onPress: this.onUsernameAlertAcknowledged }], - { cancelable: false }, - ); - } else if (e.message === 'invalid_credentials') { + if (e.message === 'invalid_credentials') { Alert.alert( - 'Incorrect password', - 'The password you entered is incorrect', - [{ text: 'OK', onPress: this.onPasswordAlertAcknowledged }], + 'Incorrect username or password', + "Either that user doesn't exist, or the password is incorrect", + [{ text: 'OK', onPress: this.onUnsuccessfulLoginAlertAckowledged }], { cancelable: false }, ); } else if (e.message === 'client_version_unsupported') { @@ -300,6 +283,27 @@ } } + onUnsuccessfulLoginAlertAckowledged: () => void = () => { + this.props.setActiveAlert(false); + this.props.logInState.setState( + { + usernameInputText: '', + passwordInputText: '', + }, + this.focusUsernameInput, + ); + }; + + onUsernameAlertAcknowledged: () => void = () => { + this.props.setActiveAlert(false); + this.props.logInState.setState( + { + usernameInputText: '', + }, + this.focusUsernameInput, + ); + }; + onPasswordAlertAcknowledged: () => void = () => { this.props.setActiveAlert(false); this.props.logInState.setState( diff --git a/web/account/log-in-form.react.js b/web/account/log-in-form.react.js --- a/web/account/log-in-form.react.js +++ b/web/account/log-in-form.react.js @@ -40,7 +40,6 @@ const [errorMessage, setErrorMessage] = React.useState(''); const usernameInputRef = React.useRef(); - const passwordInputRef = React.useRef(); React.useEffect(() => { usernameInputRef.current?.focus(); @@ -72,20 +71,14 @@ modalContext.popModal(); return result; } catch (e) { - if (e.message === 'invalid_parameters') { - setUsername(''); - setErrorMessage(`user doesn't exist`); - usernameInputRef.current?.focus(); - } else if (e.message === 'invalid_credentials') { - setPassword(''); - setErrorMessage('wrong password'); - passwordInputRef.current?.focus(); + setUsername(''); + setPassword(''); + if (e.message === 'invalid_credentials') { + setErrorMessage('incorrect username or password'); } else { - setUsername(''); - setPassword(''); setErrorMessage('unknown error'); - usernameInputRef.current?.focus(); } + usernameInputRef.current?.focus(); throw e; } }, @@ -151,7 +144,6 @@ placeholder="Password" value={password} onChange={onPasswordChange} - ref={passwordInputRef} disabled={inputDisabled} />