Password paste

pull/1005/head
Vincent 6 years ago
parent 3800ca2050
commit d6a48b9f6d

@ -2296,6 +2296,10 @@
"confirmPassword": { "confirmPassword": {
"message": "Confirm password" "message": "Confirm password"
}, },
"pasteLongPasswordToastTitle": {
"message": "The clipboard content exceeds the maximum password length of $max_pwd_len$ characters.",
"description": "Shown when user pastes a password which is longer than MAX_PASSWORD_LEN"
},
"showSeedPasswordRequest": { "showSeedPasswordRequest": {
"message": "Please enter your password", "message": "Please enter your password",
"description": "Request for user to enter password to show seed." "description": "Request for user to enter password to show seed."

@ -34,7 +34,7 @@ window.Signal.Logs = require('./js/modules/logs');
window.CONSTANTS = { window.CONSTANTS = {
MAX_LOGIN_TRIES: 3, MAX_LOGIN_TRIES: 3,
MAX_PASSWORD_LENGTH: 32, MAX_PASSWORD_LENGTH: 64,
MAX_USERNAME_LENGTH: 20, MAX_USERNAME_LENGTH: 20,
}; };

@ -64,7 +64,7 @@ window.isBeforeVersion = (toCheck, baseVersion) => {
window.CONSTANTS = { window.CONSTANTS = {
MAX_LOGIN_TRIES: 3, MAX_LOGIN_TRIES: 3,
MAX_PASSWORD_LENGTH: 32, MAX_PASSWORD_LENGTH: 64,
MAX_USERNAME_LENGTH: 20, MAX_USERNAME_LENGTH: 20,
MAX_GROUP_NAME_LENGTH: 64, MAX_GROUP_NAME_LENGTH: 64,
DEFAULT_PUBLIC_CHAT_URL: appConfig.get('defaultPublicChatServer'), DEFAULT_PUBLIC_CHAT_URL: appConfig.get('defaultPublicChatServer'),

@ -33,6 +33,7 @@ export class SessionPasswordModal extends React.Component<Props, State> {
this.closeDialog = this.closeDialog.bind(this); this.closeDialog = this.closeDialog.bind(this);
this.onKeyUp = this.onKeyUp.bind(this); this.onKeyUp = this.onKeyUp.bind(this);
this.onPaste = this.onPaste.bind(this);
} }
public componentDidMount() { public componentDidMount() {
@ -66,6 +67,7 @@ export class SessionPasswordModal extends React.Component<Props, State> {
placeholder={placeholders[0]} placeholder={placeholders[0]}
onKeyUp={this.onKeyUp} onKeyUp={this.onKeyUp}
maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH} maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH}
onPaste={this.onPaste}
/> />
{action !== PasswordAction.Remove && ( {action !== PasswordAction.Remove && (
<input <input
@ -74,6 +76,7 @@ export class SessionPasswordModal extends React.Component<Props, State> {
placeholder={placeholders[1]} placeholder={placeholders[1]}
onKeyUp={this.onKeyUp} onKeyUp={this.onKeyUp}
maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH} maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH}
onPaste={this.onPaste}
/> />
)} )}
</div> </div>
@ -191,6 +194,22 @@ export class SessionPasswordModal extends React.Component<Props, State> {
} }
} }
private onPaste(event: any) {
const clipboard = event.clipboardData.getData('text');
if (clipboard.length > window.CONSTANTS.MAX_PASSWORD_LENGTH){
const title = String(window.i18n('pasteLongPasswordToastTitle', window.CONSTANTS.MAX_PASSWORD_LENGTH));
window.pushToast({
title,
type: 'warning',
});
}
// Prevent pating into input
return false;
}
private async onKeyUp(event: any) { private async onKeyUp(event: any) {
const { onOk } = this.props; const { onOk } = this.props;

@ -25,6 +25,8 @@ export class SessionPasswordPrompt extends React.PureComponent<{}, State> {
}; };
this.onKeyUp = this.onKeyUp.bind(this); this.onKeyUp = this.onKeyUp.bind(this);
this.onPaste = this.onPaste.bind(this);
this.initLogin = this.initLogin.bind(this); this.initLogin = this.initLogin.bind(this);
this.initClearDataView = this.initClearDataView.bind(this); this.initClearDataView = this.initClearDataView.bind(this);
} }
@ -62,6 +64,7 @@ export class SessionPasswordPrompt extends React.PureComponent<{}, State> {
placeholder={' '} placeholder={' '}
onKeyUp={this.onKeyUp} onKeyUp={this.onKeyUp}
maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH} maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH}
onPaste={this.onPaste}
/> />
); );
const infoIcon = this.state.clearDataView ? ( const infoIcon = this.state.clearDataView ? (
@ -120,18 +123,31 @@ export class SessionPasswordPrompt extends React.PureComponent<{}, State> {
event.preventDefault(); event.preventDefault();
} }
public onPaste(event: any) {
const clipboard = event.clipboardData.getData('text');
if (clipboard.length > window.CONSTANTS.MAX_PASSWORD_LENGTH){
this.setState({
error: String(window.i18n('pasteLongPasswordToastTitle', window.CONSTANTS.MAX_PASSWORD_LENGTH))
});
}
// Prevent pating into input
return false;
}
public async onLogin(passPhrase: string) { public async onLogin(passPhrase: string) {
const trimmed = passPhrase ? passPhrase.trim() : passPhrase; const trimmed = passPhrase ? passPhrase.trim() : passPhrase;
try { try {
await window.onLogin(trimmed); await window.onLogin(trimmed);
} catch (e) { } catch (error) {
// Increment the error counter and show the button if necessary // Increment the error counter and show the button if necessary
this.setState({ this.setState({
errorCount: this.state.errorCount + 1, errorCount: this.state.errorCount + 1,
}); });
this.setState({ error: e }); this.setState({ error });
} }
} }

Loading…
Cancel
Save