Skip to content

Commit cf767c7

Browse files
authored
Merge pull request #8585 from sagemathinc/clarify-pw-req-8582
next/server: improve password policy
2 parents 9b82b9c + 22d936a commit cf767c7

File tree

15 files changed

+324
-35
lines changed

15 files changed

+324
-35
lines changed

src/packages/frontend/account/settings/email-address-setting.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
* License: MS-RSL – see LICENSE.md for details
44
*/
55

6-
import { FormattedMessage, useIntl } from "react-intl";
7-
import { alert_message } from "@cocalc/frontend/alerts";
86
import { Button, Card, Input, Space } from "antd";
97
import { useState } from "react";
8+
import { FormattedMessage, useIntl } from "react-intl";
9+
10+
import { alert_message } from "@cocalc/frontend/alerts";
1011
import { ErrorDisplay, LabeledRow, Saving } from "@cocalc/frontend/components";
1112
import { labels } from "@cocalc/frontend/i18n";
1213
import { log } from "@cocalc/frontend/user-tracking";
1314
import { webapp_client } from "@cocalc/frontend/webapp-client";
1415
import { COLORS } from "@cocalc/util/theme";
16+
import { MIN_PASSWORD_LENGTH } from "@cocalc/util/auth";
1517

1618
interface Props {
1719
email_address?: string;
@@ -47,9 +49,11 @@ export const EmailAddressSetting = ({
4749
}
4850

4951
async function save_editing(): Promise<void> {
50-
if (password.length < 6) {
52+
if (password.length < MIN_PASSWORD_LENGTH) {
5153
setState("edit");
52-
setError("Password must be at least 6 characters long.");
54+
setError(
55+
`Password must be at least ${MIN_PASSWORD_LENGTH} characters long.`,
56+
);
5357
return;
5458
}
5559
setState("saving");

src/packages/frontend/account/settings/password-setting.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import { appBasePath } from "@cocalc/frontend/customize/app-base-path";
2323
import { labels } from "@cocalc/frontend/i18n";
2424
import { webapp_client } from "@cocalc/frontend/webapp-client";
25+
import { MIN_PASSWORD_LENGTH } from "@cocalc/util/auth";
2526

2627
interface State {
2728
state: "view" | "edit" | "saving"; // view --> edit --> saving --> view
@@ -67,15 +68,16 @@ export const PasswordSetting: React.FC = () => {
6768
if (!is_mounted.current) return;
6869
} catch (err) {
6970
if (!is_mounted.current) return;
70-
set_state("edit"), set_error(`Error changing password -- ${err}`);
71+
set_state("edit");
72+
set_error(`Error changing password -- ${err}`);
7173
return;
7274
}
7375
reset();
7476
}
7577

7678
function is_submittable(): boolean {
7779
return !!(
78-
new_password.length >= 6 &&
80+
new_password.length >= MIN_PASSWORD_LENGTH &&
7981
new_password &&
8082
new_password !== old_password
8183
);
@@ -138,7 +140,9 @@ export const PasswordSetting: React.FC = () => {
138140
/>
139141
</Form.Item>
140142
New password
141-
{new_password.length < 6 ? " (at least 6 characters)" : undefined}
143+
{new_password.length < MIN_PASSWORD_LENGTH
144+
? ` (at least ${MIN_PASSWORD_LENGTH} characters)`
145+
: undefined}
142146
{new_password.length >= 6 && new_password == old_password
143147
? " (different than old password)"
144148
: undefined}

src/packages/next/components/account/config/account/api.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import useAPI from "lib/hooks/api";
1212
import register from "../register";
1313
import { Paragraph, Text } from "components/misc";
1414
import ApiKeys from "@cocalc/frontend/components/api-keys";
15+
import { MIN_PASSWORD_LENGTH } from "@cocalc/util/auth";
1516

1617
register({
1718
path: "account/api",
@@ -96,14 +97,14 @@ register({
9697
placeholder="Enter your password..."
9798
onChange={(e) => setPassword(e.target.value)}
9899
onPressEnter={() => {
99-
if (password.length >= 6) {
100+
if (password.length >= MIN_PASSWORD_LENGTH) {
100101
submitPassword(password);
101102
}
102103
}}
103104
/>
104105
<Button
105106
style={{ marginLeft: "15px" }}
106-
disabled={password.length < 6}
107+
disabled={password.length < MIN_PASSWORD_LENGTH}
107108
onClick={() => submitPassword(password)}
108109
>
109110
Show Older Legacy API Key

src/packages/next/components/account/config/account/email.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ import { Alert, Button, Input, Space } from "antd";
77
import { useEffect, useMemo, useState, type JSX } from "react";
88

99
import { Icon } from "@cocalc/frontend/components/icon";
10+
import { MIN_PASSWORD_LENGTH } from "@cocalc/util/auth";
1011
import { is_valid_email_address as isValidEmailAddress } from "@cocalc/util/misc";
1112
import { Paragraph, Text, Title } from "components/misc";
1213
import SaveButton from "components/misc/save-button";
1314
import Timestamp from "components/misc/timestamp";
1415
import Loading from "components/share/loading";
1516
import apiPost from "lib/api/post";
17+
import { useCustomize } from "lib/customize";
1618
import useAPI from "lib/hooks/api";
1719
import useDatabase from "lib/hooks/database";
1820
import register from "../register";
19-
import { useCustomize } from "lib/customize";
2021

2122
interface Data {
2223
email_address?: string;
@@ -107,7 +108,7 @@ export function ChangeEmailAddress(props: Props) {
107108
/>
108109
<SaveButton
109110
disabled={
110-
password.length < 6 ||
111+
password.length < MIN_PASSWORD_LENGTH ||
111112
!isValidEmailAddress(edited.email_address ?? "") ||
112113
lastSuccess == password + (edited.email_address ?? "")
113114
}
@@ -121,7 +122,7 @@ export function ChangeEmailAddress(props: Props) {
121122
});
122123
setLastSuccess(password + email_address);
123124
}}
124-
isValid={() => password.length >= 6}
125+
isValid={() => password.length >= MIN_PASSWORD_LENGTH}
125126
/>
126127
{lastSuccess == password + edited.email_address && (
127128
<Alert

src/packages/next/components/account/config/account/password.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import { Alert, Button, Input, Space } from "antd";
77
import { useState } from "react";
88

9-
import { Title, Text, Paragraph } from "components/misc";
9+
import { MIN_PASSWORD_LENGTH } from "@cocalc/util/auth";
10+
import { Paragraph, Text, Title } from "components/misc";
1011
import A from "components/misc/A";
1112
import Loading from "components/share/loading";
1213
import apiPost from "lib/api/post";
@@ -76,14 +77,14 @@ register({
7677
}}
7778
onPressEnter={resetPassword}
7879
/>
79-
(at least 6 characters)
80+
(at least {MIN_PASSWORD_LENGTH} characters)
8081
</Paragraph>
8182
<Button
8283
type="primary"
8384
disabled={
8485
(changed && changed == newPassword) ||
8586
changing ||
86-
newPassword.length < 6 ||
87+
newPassword.length < MIN_PASSWORD_LENGTH ||
8788
newPassword == currentPassword
8889
}
8990
onClick={resetPassword}

src/packages/next/components/account/config/anonymous/upgrade.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { delay } from "awaiting";
88
import { CSSProperties, useState } from "react";
99

1010
import { Icon } from "@cocalc/frontend/components/icon";
11+
import { MIN_PASSWORD_LENGTH } from "@cocalc/util/auth";
1112
import { is_valid_email_address as isValidEmailAddress } from "@cocalc/util/misc";
1213
import { TermsCheckbox } from "components/auth/sign-up";
1314
import SSO from "components/auth/sso";
@@ -100,7 +101,9 @@ function EmailPassword() {
100101
{/* change height of button to match input boxes */}
101102
<Button
102103
type="primary"
103-
disabled={success || !email_address || password.length < 6}
104+
disabled={
105+
success || !email_address || password.length < MIN_PASSWORD_LENGTH
106+
}
104107
style={{ height: "35px" }}
105108
onClick={setEmailAndPassword}
106109
>
@@ -111,8 +114,8 @@ function EmailPassword() {
111114
) : email_address.length > 0 &&
112115
!isValidEmailAddress(email_address) ? (
113116
"Enter valid email"
114-
) : password.length > 0 && password.length < 6 ? (
115-
"At least 6 characters"
117+
) : password.length > 0 && password.length < MIN_PASSWORD_LENGTH ? (
118+
`At least ${MIN_PASSWORD_LENGTH} characters`
116119
) : (
117120
<>
118121
<Icon name="check" style={{ marginRight: "5px" }} /> Save

0 commit comments

Comments
 (0)