ts: Convert password_quality module to TypeScript.

This commit is contained in:
Priyank Patel 2021-07-03 17:51:37 +00:00 committed by Tim Abbott
parent 5a65a47b21
commit fdedced521
4 changed files with 14 additions and 4 deletions

View File

@ -92,6 +92,7 @@
"@types/terser-webpack-plugin": "^4.1.0",
"@types/webpack": "^4.4.32",
"@types/webpack-dev-server": "^3.1.6",
"@types/zxcvbn": "^4.4.1",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"babel-plugin-rewire-ts": "^1.4.0",

View File

@ -9,7 +9,11 @@ import {$t} from "./i18n";
// Return a boolean indicating whether the password is acceptable.
// Also updates a Bootstrap progress bar control (a jQuery object)
// if provided.
export function password_quality(password, bar, password_field) {
export function password_quality(
password: string,
bar: JQuery | undefined,
password_field: JQuery,
): boolean {
const min_length = password_field.data("minLength");
const min_guesses = password_field.data("minGuesses");
@ -17,7 +21,7 @@ export function password_quality(password, bar, password_field) {
const acceptable = password.length >= min_length && result.guesses >= min_guesses;
if (bar !== undefined) {
const t = result.crack_times_seconds.offline_slow_hashing_1e4_per_second;
const t = Number(result.crack_times_seconds.offline_slow_hashing_1e4_per_second);
let bar_progress = Math.min(1, Math.log(1 + t) / 22);
// Even if zxcvbn loves your short password, the bar should be
@ -36,7 +40,7 @@ export function password_quality(password, bar, password_field) {
return acceptable;
}
export function password_warning(password, password_field) {
export function password_warning(password: string, password_field: JQuery): string {
const min_length = password_field.data("minLength");
if (password.length < min_length) {

View File

@ -48,4 +48,4 @@ API_FEATURE_LEVEL = 77
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
PROVISION_VERSION = "153.1"
PROVISION_VERSION = "153.2"

View File

@ -1775,6 +1775,11 @@
dependencies:
"@types/node" "*"
"@types/zxcvbn@^4.4.1":
version "4.4.1"
resolved "https://registry.yarnpkg.com/@types/zxcvbn/-/zxcvbn-4.4.1.tgz#46e42cbdcee681b22181478feaf4af2bc4c1abd2"
integrity sha512-3NoqvZC2W5gAC5DZbTpCeJ251vGQmgcWIHQJGq2J240HY6ErQ9aWKkwfoKJlHLx+A83WPNTZ9+3cd2ILxbvr1w==
"@typescript-eslint/eslint-plugin@^4.0.1":
version "4.28.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.28.2.tgz#7a8320f00141666813d0ae43b49ee8244f7cf92a"