Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: Debounce password quality checking during typing #19591

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions pkg/lib/cockpit-components-password.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import cockpit from 'cockpit';
import React, { useState } from 'react';
import { debounce } from 'throttle-debounce';
import { Button } from '@patternfly/react-core/dist/esm/components/Button/index.js';
import { FormGroup, FormHelperText } from "@patternfly/react-core/dist/esm/components/Form/index.js";
import { InputGroup, InputGroupItem } from '@patternfly/react-core/dist/esm/components/InputGroup/index.js';
Expand Down Expand Up @@ -54,6 +55,10 @@ export function password_quality(password, force) {
});
}

const debounced_password_quality = debounce(300, (value, callback) => {
password_quality(value).catch(() => ({ value: 0 })).then(callback);
});

export const PasswordFormFields = ({
password_label, password_confirm_label,
password_label_info,
Expand All @@ -73,14 +78,10 @@ export const PasswordFormFields = ({
change("password", value);

if (value) {
password_quality(value)
.catch(() => {
return { value: 0 };
})
.then(strength => {
setPasswordStrength(strength.value);
setPasswordMessage(strength.message);
});
debounced_password_quality(value, strength => {
setPasswordStrength(strength.value);
setPasswordMessage(strength.message);
});
} else {
setPasswordStrength();
setPasswordMessage("");
Expand Down