From 12d5ba8d157fc319d0866b0d7d83f1a48c3aa181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Mon, 19 Oct 2026 15:31:59 -0300 Subject: [PATCH] feat: passwords need 8 characters or more, on the Site and in the Kanban Co-Authored-By: Claude Opus 5.5 --- app/api/users.py | 6 +++--- app/core/models.py | 6 +++--- app/operators.py | 2 +- docs/LOCAL_SETUP.md | 2 +- tests/users_test.py | 6 +++++- web/kanban.js | 10 +++++----- web/portal.html | 12 ++++++------ web/portal.js | 6 +++--- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/api/users.py b/app/api/users.py index 67da42d..a948539 100644 --- a/app/api/users.py +++ b/app/api/users.py @@ -26,7 +26,7 @@ class UserIn(StrictModel): name: str = Field(min_length=1, max_length=80) email: str = Field(min_length=3, max_length=254) role: Literal['admin', 'gestao', 'operador', 'vendedor'] - password: str | None = Field(default=None, min_length=12, max_length=128) + password: str | None = Field(default=None, min_length=8, max_length=128) active: bool = True machines: list[UUID] = Field(default_factory=list, max_length=50) # The team's alerts by e-mail: orders paid, carts waiting for review, payments to look at. @@ -49,7 +49,7 @@ class MachineIn(StrictModel): class PasswordChange(StrictModel): current: str = Field(min_length=1, max_length=128) - new: str = Field(min_length=12, max_length=128) + new: str = Field(min_length=8, max_length=128) @router.get('/api/operator/me') @@ -112,7 +112,7 @@ def set_machines(c, uid, machines): @router.post('/api/operator/users') def create_user(body: UserIn, request: Request, user=Depends(can('users'))): if not body.password: - raise HTTPException(422, 'Defina uma senha inicial com 12 caracteres ou mais.') + raise HTTPException(422, 'Defina uma senha inicial com 8 caracteres ou mais.') uid = uuid4() with db.connect() as c: if c.execute('SELECT 1 FROM dtf_local.operators WHERE email=%s', (body.email,)).fetchone(): diff --git a/app/core/models.py b/app/core/models.py index 5990413..b7d6564 100644 --- a/app/core/models.py +++ b/app/core/models.py @@ -255,7 +255,7 @@ class Resolution(StrictModel): class Register(StrictModel): customer: Customer - password: str = Field(min_length=12, max_length=128) + password: str = Field(min_length=8, max_length=128) class ProfileUpdate(StrictModel): """What a customer may change about their account; the CPF/CNPJ is not among it.""" @@ -290,7 +290,7 @@ class EmailChange(StrictModel): class PasswordChange(StrictModel): current: str = Field(min_length=1, max_length=128) - new: str = Field(min_length=12, max_length=128) + new: str = Field(min_length=8, max_length=128) class SignupCode(StrictModel): signup: UUID @@ -311,7 +311,7 @@ class ForgotPassword(StrictModel): class PasswordReset(StrictModel): token: str = Field(min_length=20, max_length=100, pattern=r'^[A-Za-z0-9_-]+$') - password: str = Field(min_length=12, max_length=128) + password: str = Field(min_length=8, max_length=128) class Login(StrictModel): email: str = Field(min_length=3, max_length=254) diff --git a/app/operators.py b/app/operators.py index e0e79b6..364e691 100644 --- a/app/operators.py +++ b/app/operators.py @@ -28,7 +28,7 @@ from uuid import uuid4 from .core.auth import ROLES, password_hash from .core.db import connect -MIN_PASSWORD = 12 +MIN_PASSWORD = 8 def seed_from_environment(cursor): diff --git a/docs/LOCAL_SETUP.md b/docs/LOCAL_SETUP.md index da40841..bb88ce1 100644 --- a/docs/LOCAL_SETUP.md +++ b/docs/LOCAL_SETUP.md @@ -109,7 +109,7 @@ final files are separately labeled. Never print the local text fixture. ## Customer accounts, corrections, and cart recovery Open **Minha conta** on the Site, or `/portal.html`. Create a local account with -a test CNPJ, phone, email and password of at least 12 characters. Passwords use +a test CNPJ, phone, email and password of at least 8 characters. Passwords use the current stronger scrypt format; legacy local hashes are verified and upgraded on successful login. Sessions are stored in PostgreSQL, expire after seven days, and are revoked on logout. Login/registration attempts are limited. diff --git a/tests/users_test.py b/tests/users_test.py index b246e6b..9573e08 100644 --- a/tests/users_test.py +++ b/tests/users_test.py @@ -92,7 +92,11 @@ def run(): assert seller.call('/operator/me')['can'] == ['view'] # Their own password: the current one is asked for. seller.call('/operator/me/password', {'current': 'errada', 'new': 'outra-senha-de-teste'}, expected=403) - seller.call('/operator/me/password', {'current': PASSWORD, 'new': 'outra-senha-de-teste'}) + # Eight characters or more. + seller.call('/operator/me/password', {'current': PASSWORD, 'new': 'sete-77'}, expected=422) + seller.call('/operator/me/password', {'current': PASSWORD, 'new': 'oito-888'}) + seller = signed_in(emails['vendedor'], 'oito-888') + seller.call('/operator/me/password', {'current': 'oito-888', 'new': 'outra-senha-de-teste'}) signed_in(emails['vendedor'], 'outra-senha-de-teste').call('/operator/me') # Disabled, the operator is out at once; deleted, the account is gone. diff --git a/web/kanban.js b/web/kanban.js index a0f5a73..c00a4fe 100644 --- a/web/kanban.js +++ b/web/kanban.js @@ -1139,8 +1139,8 @@ function userForm(u){ const roles=u?.role==='superadmin'?['superadmin']:['admin','gestao','operador','vendedor']; for(const r of roles){const o=node('option',ROLE_NAMES[r]);o.value=r;role.append(o);} role.value=u?.role||'operador';role.disabled=u?.role==='superadmin'||u?.email===ME.email; - const pass=node('input');pass.type='password';pass.minLength=12;pass.maxLength=128;pass.autocomplete='new-password'; - pass.required=!editing;pass.placeholder=editing?'Deixe em branco para manter':'12 caracteres ou mais'; + const pass=node('input');pass.type='password';pass.minLength=8;pass.maxLength=128;pass.autocomplete='new-password'; + pass.required=!editing;pass.placeholder=editing?'Deixe em branco para manter':'8 caracteres ou mais'; const active=node('input');active.type='checkbox';active.checked=u?u.active:true;active.disabled=u?.email===ME.email; const activeLabel=node('label',undefined,'check');activeLabel.append(active,'Ativo (pode entrar no Kanban)'); const alerts=node('input');alerts.type='checkbox';alerts.checked=!!u?.alerts; @@ -1174,9 +1174,9 @@ function machineForm(m){ } function passwordForm(){ const current=node('input');current.type='password';current.required=true;current.autocomplete='current-password'; - const next=node('input');next.type='password';next.required=true;next.minLength=12;next.autocomplete='new-password'; - const again=node('input');again.type='password';again.required=true;again.minLength=12;again.autocomplete='new-password'; - dialog('Minha senha',[field('Senha atual',current),field('Nova senha (12 caracteres ou mais)',next),field('Repita a nova senha',again)],async()=>{ + const next=node('input');next.type='password';next.required=true;next.minLength=8;next.autocomplete='new-password'; + const again=node('input');again.type='password';again.required=true;again.minLength=8;again.autocomplete='new-password'; + dialog('Minha senha',[field('Senha atual',current),field('Nova senha (8 caracteres ou mais)',next),field('Repita a nova senha',again)],async()=>{ if(next.value!==again.value)throw new Error('A nova senha e a repetição não conferem.'); await api('/me/password',{current:current.value,new:next.value});say('Senha trocada.'); }); diff --git a/web/portal.html b/web/portal.html index 7a2cb25..b475e26 100644 --- a/web/portal.html +++ b/web/portal.html @@ -66,8 +66,8 @@ - - + + @@ -93,10 +93,10 @@

Nova senha

Depois de salvar, você já entra na sua conta.

- - + + - +
@@ -188,7 +188,7 @@

Senha

- +
diff --git a/web/portal.js b/web/portal.js index 5bdae17..d4822f4 100644 --- a/web/portal.js +++ b/web/portal.js @@ -361,7 +361,7 @@ $('fSenha').onsubmit=async event=>{ event.preventDefault(); try{await api('/account/password',{current:$('dAtual').value,new:$('dNova').value}); $('dAtual').value='';$('dNova').value='';aviso('Senha alterada.');} - catch(e){aviso(e.status===422?'A nova senha precisa ter 12 caracteres ou mais.':e.message,true);} + catch(e){aviso(e.status===422?'A nova senha precisa ter 8 caracteres ou mais.':e.message,true);} }; // ---- Signing in ---------------------------------------------------------- @@ -388,7 +388,7 @@ async function authenticate(path,body,destino){ $('login').onsubmit=async event=>{event.preventDefault();try{await authenticate('/account/login',{email:$('email').value,password:$('password').value});}catch(e){aviso(e.message,true);}}; $('register').onsubmit=async event=>{event.preventDefault();$('criarConta').disabled=true; try{await authenticate('/account/register',{customer:{name:$('register-name').value,cnpj:$('cnpj').value,zap:$('phone').value,mail:$('register-email').value},password:$('register-password').value});} - catch(e){aviso(e.status===422?'Confira o nome, o CPF ou CNPJ, o WhatsApp e o e-mail. A senha precisa ter 12 caracteres ou mais.':e.message,true);} + catch(e){aviso(e.status===422?'Confira o nome, o CPF ou CNPJ, o WhatsApp e o e-mail. A senha precisa ter 8 caracteres ou mais.':e.message,true);} finally{$('criarConta').disabled=false;}}; // Signup code: the account is created only once the code e-mailed to the @@ -460,7 +460,7 @@ $('fRedefinir').onsubmit=async event=>{ if($('rNova').value!==$('rRepete').value){aviso('A nova senha e a repetição não conferem.',true);return;} try{await authenticate('/account/reset',{token:resetToken,password:$('rNova').value},'/conta'); resetToken='';$('rNova').value='';$('rRepete').value='';aviso('Senha criada. Você já está na sua conta.');} - catch(e){aviso(e.status===422?(resetToken?'A nova senha precisa ter 12 caracteres ou mais.':'Este link está incompleto. Peça outro em “Esqueci minha senha”.'):e.message,true);} + catch(e){aviso(e.status===422?(resetToken?'A nova senha precisa ter 8 caracteres ou mais.':'Este link está incompleto. Peça outro em “Esqueci minha senha”.'):e.message,true);} }; $('logout').onclick=async()=>{try{await window.dtfForgetPrivateData();await api('/account/logout',{});location.assign('/conta/entrar');}catch(error){aviso('Não foi possível limpar os dados deste navegador. Feche as abas do Site e limpe os dados do site nas configurações do navegador.',true);}};