Skip to content

Commit

Permalink
ts: Convert password_quality module to TypeScript.
Browse files Browse the repository at this point in the history
  • Loading branch information
priyank-p authored and timabbott committed Jul 9, 2021
1 parent 5a65a47 commit fdedced
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions static/js/password_quality.js → static/js/password_quality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ 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");

const result = zxcvbn(password);
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
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
# historical commits sharing the same major version, in which case a
# minor version bump suffices.

PROVISION_VERSION = "153.1"
PROVISION_VERSION = "153.2"
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fdedced

Please sign in to comment.