Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(signup): show a weak password error on the password step (#116902)

Eleftheria Trivyzaki769d5ccda6bd
diff --git a/frontend/src/lib/components/PasswordStrength.tsx b/frontend/src/lib/components/PasswordStrength.tsx
index 6fa74a9929e7..a2012ca40f1b 100644
--- a/frontend/src/lib/components/PasswordStrength.tsx
+++ b/frontend/src/lib/components/PasswordStrength.tsx
@@ -8,9 +8,17 @@ export type ValidatedPasswordResult = {
feedback?: string
}
-let zxcvbnFn: ((password: string) => { score: number; feedback: { suggestions: string[] } }) | null = null
+let zxcvbnFn: ((password: string) => { score: number; feedback: { warning: string } }) | null = null
let zxcvbnLoading = false
+const PASSWORD_NEXT_STEP = "Try a longer password that isn't a common word or pattern."
+
+// zxcvbn's suggestions assume passphrases ("Add another word or two"), so only its warning is
+// shown, which names the weakness it found
+function weakPasswordFeedback(warning: string): string {
+ return warning ? `${warning}. ${PASSWORD_NEXT_STEP}` : `This password is too easy to guess. ${PASSWORD_NEXT_STEP}`
+}
+
// We load zxcvbn asynchronously as it's a large dependency and we don't want to block the main thread
function ensureZxcvbnLoaded(): void {
if (!zxcvbnFn && !zxcvbnLoading) {
@@ -42,19 +50,20 @@ export function validatePassword(password: string = ''): ValidatedPasswordResult
}
}
+ if (!password) {
+ return { score: 0 }
+ }
+
if (!zxcvbnFn) {
// Return basic length-based validation while zxcvbn is loading
- if (!password) {
- return { score: 0 }
- }
return { score: 3, feedback: '' }
}
const result = zxcvbnFn(password)
return {
- score: password ? result.score + 1 : 0,
- feedback: result.feedback.suggestions.join(' '),
+ score: result.score + 1,
+ feedback: result.score < 3 ? weakPasswordFeedback(result.feedback.warning) : '',
}
}
diff --git a/frontend/src/scenes/authentication/signup/signupForm/signupLogic.test.ts b/frontend/src/scenes/authentication/signup/signupForm/signupLogic.test.ts
index f7c9627b2f97..daa9975e0e21 100644
--- a/frontend/src/scenes/authentication/signup/signupForm/signupLogic.test.ts
+++ b/frontend/src/scenes/authentication/signup/signupForm/signupLogic.test.ts
@@ -347,6 +347,80 @@ describe('signupLogic — name handling', () => {
expect(logic.values.signupPanelOnboardingErrors.name).toBe('This field may not be blank.')
expect(logic.values.panel).toBe(2)
})
+
+ it('sends a password API error back to the password step and lets the next submit through', async () => {
+ useMocks({
+ post: {
+ '/api/signup/': () => [
+ 400,
+ {
+ type: 'validation_error',
+ code: 'password_too_weak',
+ detail: 'Add another word or two. Uncommon words are better.',
+ attr: 'password',
+ },
+ ],
+ },
+ })
+ await advanceToOnboardingPanel()
+ logic.actions.setSignupPanelOnboardingValues({
+ name: 'John Smith',
+ organization_name: 'Hogflix',
+ role_at_organization: 'engineer',
+ referral_source: '',
+ referral_source_ai_prompt: '',
+ })
+ logic.actions.submitSignupPanelOnboarding()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.panel).toBe(1)
+ expect(logic.values.signupPanelAuthManualErrors.password).toBe(
+ 'Add another word or two. Uncommon words are better.'
+ )
+ expect(logic.values.signupPanelOnboardingManualErrors.generic).toBeUndefined()
+
+ logic.actions.setSignupPanelAuthValue('password', 'An0ther-Str0ng-Pass!')
+ logic.actions.submitSignupPanelAuth()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.panel).toBe(2)
+ expect(logic.values.signupPanelAuthManualErrors.password).toBeUndefined()
+ })
+
+ it('drops a stale password error when a different email is submitted', async () => {
+ useMocks({
+ post: {
+ '/api/signup/': () => [
+ 400,
+ {
+ type: 'validation_error',
+ code: 'password_too_weak',
+ detail: 'Add another word or two. Uncommon words are better.',
+ attr: 'password',
+ },
+ ],
+ },
+ })
+ await advanceToOnboardingPanel()
+ logic.actions.setSignupPanelOnboardingValues({
+ name: 'John Smith',
+ organization_name: 'Hogflix',
+ role_at_organization: 'engineer',
+ referral_source: '',
+ referral_source_ai_prompt: '',
+ })
+ logic.actions.submitSignupPanelOnboarding()
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.signupPanelAuthManualErrors.password).toBeTruthy()
+
+ logic.actions.setPanel(0)
+ logic.actions.setSignupPanelEmailValue('email', '[email protected]')
+ logic.actions.submitSignupPanelEmail()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.panel).toBe(1)
+ expect(logic.values.signupPanelAuthManualErrors.password).toBeUndefined()
+ })
})
describe('signupLogic - pending OAuth connection', () => {
diff --git a/frontend/src/scenes/authentication/signup/signupForm/signupLogic.ts b/frontend/src/scenes/authentication/signup/signupForm/signupLogic.ts
index d5408f766219..4e6123460b15 100644
--- a/frontend/src/scenes/authentication/signup/signupForm/signupLogic.ts
+++ b/frontend/src/scenes/authentication/signup/signupForm/signupLogic.ts
@@ -425,6 +425,7 @@ export const signupLogic = kea<signupLogicType>([
submit: async ({ email }, breakpoint) => {
breakpoint()
actions.setPasskeyError(null)
+ actions.setSignupPanelAuthManualErrors({})
let precheckResponse: SignupEmailPrecheckResponse
try {
// nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. No generated function covers this endpoint yet. Find out why the generated client skips it (no schema, no product tag, or excluded from the spec) and fix that first.
@@ -476,6 +477,11 @@ export const signupLogic = kea<signupLogicType>([
: values.validatedPassword.feedback || undefined
: undefined,
}),
+ // Same reason as the email panel: a manual error left behind by the server would block
+ // every later submit of this form.
+ preSubmit: () => {
+ actions.setSignupPanelAuthManualErrors({})
+ },
submit: async () => {
actions.setPanel(2)
},
@@ -570,6 +576,17 @@ export const signupLogic = kea<signupLogicType>([
return
}
+ // The strength meter fails open while its zxcvbn chunk is loading, so a password it
+ // never scored can reach the server and be refused there. Send the user back to the
+ // password step.
+ if (error.attr === 'password') {
+ actions.setSignupPanelAuthManualErrors({
+ password: String(error.detail || 'Please choose a stronger password'),
+ })
+ actions.setPanel(1)
+ return
+ }
+
// The `name` input is split into first_name/last_name for the API — surface
// errors on those attributes next to the field the user actually sees.
// Must throw (not return) so kea-forms marks the submit as failed and keeps
diff --git a/posthog/api/test/test_signup.py b/posthog/api/test/test_signup.py
index 61870aa3eb26..f15cf0fbf0bc 100644
--- a/posthog/api/test/test_signup.py
+++ b/posthog/api/test/test_signup.py
@@ -704,13 +704,15 @@ class TestSignupAPI(APIBaseTest):
self.assertEqual(Team.objects.count(), team_count)
def test_cant_sign_up_with_weak_passwords(self):
+ next_step = "Try a longer password that isn't a common word or pattern."
cases = [
- ["password", "Add another word or two. Uncommon words are better."],
+ ["password", f"This is a top-10 common password. {next_step}"],
[
"test test test",
- "Add another word or two. Uncommon words are better. Avoid repeated words and characters.",
+ f'Repeats like "abcabcabc" are only slightly harder to guess than "abc". {next_step}',
],
- ["12345678", "Add another word or two. Uncommon words are better."],
+ ["12345678", f"This is a top-10 common password. {next_step}"],
+ ["correcthorse", f"This password is too easy to guess. {next_step}"],
]
for password, detail in cases:
diff --git a/posthog/auth.py b/posthog/auth.py
index a0aea9c0f097..02dfe228de81 100644
--- a/posthog/auth.py
+++ b/posthog/auth.py
@@ -201,6 +201,8 @@ class ZxcvbnValidator:
Validate that the password satisfies zxcvbn
"""
+ NEXT_STEP = "Try a longer password that isn't a common word or pattern."
+
def __init__(self, min_length=8):
self.min_length = min_length
@@ -208,10 +210,12 @@ class ZxcvbnValidator:
result = zxcvbn(password)
if result["score"] < 3:
- joined_feedback = " ".join(result["feedback"]["suggestions"])
+ # zxcvbn's suggestions assume passphrases ("Add another word or two"), so only its
+ # warning is shown, which names the weakness it found
+ warning = result["feedback"]["warning"] or "This password is too easy to guess."
raise ValidationError(
- joined_feedback or "This password is too weak.",
+ f"{warning} {self.NEXT_STEP}",
code="password_too_weak",
)