Password whitespace trim on set

pull/1035/head
Vincent 6 years ago
parent 24114bab8d
commit 640999ab61

@ -20,6 +20,9 @@ interface State {
} }
export class SessionPasswordModal extends React.Component<Props, State> { export class SessionPasswordModal extends React.Component<Props, State> {
private readonly passwordInput: React.RefObject<HTMLInputElement>;
private readonly passwordInputConfirm: React.RefObject<HTMLInputElement>;
constructor(props: any) { constructor(props: any) {
super(props); super(props);
@ -34,10 +37,13 @@ export class SessionPasswordModal extends React.Component<Props, State> {
this.onKeyUp = this.onKeyUp.bind(this); this.onKeyUp = this.onKeyUp.bind(this);
this.onPaste = this.onPaste.bind(this); this.onPaste = this.onPaste.bind(this);
this.passwordInput = React.createRef();
this.passwordInputConfirm = React.createRef();
} }
public componentDidMount() { public componentDidMount() {
setTimeout(() => $('#password-modal-input').focus(), 100); setTimeout(() => this.passwordInput.current?.focus(), 100);
} }
public render() { public render() {
@ -64,6 +70,7 @@ export class SessionPasswordModal extends React.Component<Props, State> {
<input <input
type="password" type="password"
id="password-modal-input" id="password-modal-input"
ref={this.passwordInput}
placeholder={placeholders[0]} placeholder={placeholders[0]}
onKeyUp={this.onKeyUp} onKeyUp={this.onKeyUp}
maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH} maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH}
@ -73,6 +80,7 @@ export class SessionPasswordModal extends React.Component<Props, State> {
<input <input
type="password" type="password"
id="password-modal-input-confirm" id="password-modal-input-confirm"
ref={this.passwordInputConfirm}
placeholder={placeholders[1]} placeholder={placeholders[1]}
onKeyUp={this.onKeyUp} onKeyUp={this.onKeyUp}
maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH} maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH}
@ -126,16 +134,19 @@ export class SessionPasswordModal extends React.Component<Props, State> {
} }
private async setPassword(onSuccess: any) { private async setPassword(onSuccess: any) {
const enteredPassword = String($('#password-modal-input').val()); if (!this.passwordInput.current || !this.passwordInputConfirm.current) {
const enteredPasswordConfirm = String( return;
$('#password-modal-input-confirm').val() }
);
// Trim leading / trailing whitespace for UX
const enteredPassword = String(this.passwordInput.current.value).trim();
const enteredPasswordConfirm = String(this.passwordInputConfirm.current.value).trim();
if (enteredPassword.length === 0 || enteredPasswordConfirm.length === 0) { if (enteredPassword.length === 0 || enteredPasswordConfirm.length === 0) {
return; return;
} }
// Check passwords enntered // Check passwords entered
if ( if (
enteredPassword.length === 0 || enteredPassword.length === 0 ||
(this.props.action === PasswordAction.Change && (this.props.action === PasswordAction.Change &&

Loading…
Cancel
Save