{"record":{"id":"497cc000f7e1f00b","repo":"moghtech/komodo","slug":"password-cannot-be-empty","errorCode":null,"errorMessage":"Password cannot be empty.","messagePattern":"Password cannot be empty\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"lib/database/src/lib.rs","lineNumber":123,"sourceCode":"      procedures: resource_collection(&db, \"Procedure\").await?,\n      actions: resource_collection(&db, \"Action\").await?,\n      resource_syncs: resource_collection(&db, \"ResourceSync\")\n        .await?,\n      stacks: resource_collection(&db, \"Stack\").await?,\n      //\n      db,\n    };\n    Ok(client)\n  }\n\n  /// Updates a user's password using a DB call.\n  pub async fn set_user_password(\n    &self,\n    user: &User,\n    password: &str,\n  ) -> anyhow::Result<()> {\n    if password.is_empty() {\n      return Err(anyhow!(\"Password cannot be empty.\"));\n    }\n    let hashed_password =\n      hash_password(password).context(\"Failed to hash password\")?;\n    self.set_user_hashed_password(user, hashed_password).await\n  }\n\n  /// Updates a user's password using a DB call.\n  pub async fn set_user_hashed_password(\n    &self,\n    user: &User,\n    hashed_password: String,\n  ) -> anyhow::Result<()> {\n    let update = match user.config {\n      UserConfig::Service { .. } => {\n        return Err(anyhow!(\n          \"Service Users cannot add additional login methods\"\n        ));\n      }","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/moghtech/komodo/blob/780ac68b992094a9fccd5fffb760e0c84fd3c3d1/lib/database/src/lib.rs#L105-L141","documentation":"set_user_password validates the plaintext password before hashing it and rejects empty strings up front with this error. The library refuses to create an empty password credential because an empty password would be meaningless/unusable for authentication.","triggerScenarios":"Calling set_user_password with password == \"\" on a User record.","commonSituations":"UI or CLI signup flows with missing client-side validation passing an empty string; migration scripts importing users with blank password fields; form submission where the password field was never filled.","solutions":["Ensure the caller supplies a non-empty password string before invoking the API","Validate on the UI/form layer that the password field is non-empty (and ideally meets length policy)","Skip or guard the call in import/migration code when the password is blank","Return a user-facing 'password required' message instead of passing an empty value through"],"exampleFix":"// before\nuser_password::set(db, &user, form.password.as_deref().unwrap_or(\"\")).await?;\n// after\nlet pw = form.password.as_deref().unwrap_or(\"\");\nif pw.is_empty() { bail!(\"password is required\"); }\nuser_password::set(db, &user, pw).await?;","handlingStrategy":"validation","validationCode":"fn validate_password(password: &str) -> Result<(), String> {\n  if password.is_empty() { return Err(\"password is required\".into()); }\n  if password.len() < 8 { return Err(\"password too short\".into()); }\n  Ok(())\n}","typeGuard":null,"tryCatchPattern":"match db.set_user_password(&user, &pw).await {\n  Err(e) if e.to_string() == \"Password cannot be empty.\" => {\n    return Err(FieldError::new(\"password\", \"must not be empty\"));\n  }\n  other => other,\n}","preventionTips":["Validate non-empty (and length policy) passwords in the UI/CLI before calling the API","Unwrap optional password form fields explicitly rather than defaulting to \"\"","Reject blank password fields in migration/import scripts"],"tags":["validation","password","authentication","empty-value"],"backgroundTag":"empty-required-field","analyzedSha":"780ac68b992094a9fccd5fffb760e0c84fd3c3d1","analyzedAt":"2026-09-08T10:02:44.861Z","contentChangedAt":"2026-09-08T10:02:44.861Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}