Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Convert `lib/security` to TypeScript (#69422)

Fraser2a12752ec72a
diff --git a/frontend/src/metabase-types/api/settings.ts b/frontend/src/metabase-types/api/settings.ts
index 144685d3c47..f34f9f999b6 100644
--- a/frontend/src/metabase-types/api/settings.ts
+++ b/frontend/src/metabase-types/api/settings.ts
@@ -363,6 +363,9 @@ export type TokenFeatures = Record<TokenFeature, boolean>;
export type PasswordComplexity = {
total?: number;
digit?: number;
+ upper?: number;
+ lower?: number;
+ special?: number;
};
export type SessionCookieSameSite = "lax" | "strict" | "none";
diff --git a/frontend/src/metabase/lib/security.js b/frontend/src/metabase/lib/security.ts
similarity index 79%
rename from frontend/src/metabase/lib/security.js
rename to frontend/src/metabase/lib/security.ts
index 9fc8914884f..09d2d402bdc 100644
--- a/frontend/src/metabase/lib/security.js
+++ b/frontend/src/metabase/lib/security.ts
@@ -1,12 +1,13 @@
import passwordGenerator from "password-generator";
import MetabaseSettings from "metabase/lib/settings";
+import type { PasswordComplexity } from "metabase-types/api";
// generate a password that satisfies `complexity` requirements, by default the ones that come back in the
// `password-complexity` Setting; must be a map like {total: 6, number: 1}
-export const generatePassword = (complexity) => {
- complexity =
- complexity || MetabaseSettings.passwordComplexityRequirements() || {};
+export const generatePassword = (complexityParam?: PasswordComplexity) => {
+ const complexity =
+ complexityParam || MetabaseSettings.passwordComplexityRequirements() || {};
// generated password must be at least `complexity.total`, but can be longer
// so hard code a minimum of 14
const len = Math.max(complexity.total || 0, 14);
@@ -19,7 +20,7 @@ export const generatePassword = (complexity) => {
}
return password;
- function isStrongEnough(password) {
+ function isStrongEnough(password: string) {
const uc = password.match(/([A-Z])/g);
const lc = password.match(/([a-z])/g);
const di = password.match(/([\d])/g);