JavaScript Python PHP
async function executar(values = { "password": "UmaSenha!2026Exemplo" }) {
function assessPassword(password) {
const length = [...password].length;
const groups = [/[a-z]/, /[A-Z]/, /\d/, /[^a-zA-Z0-9]/].filter(pattern => pattern.test(password)).length;
const common = /^(password|senha|admin|qwerty|letmein|welcome|123456|abc123)(\d|[!@#$])*$/i.test(password);
const repeated = /^(.{1,4})\1+$/u.test(password);
const sequences = /(012345|123456|234567|abcdef|qwerty|asdfgh)/i.test(password);
let score = length < 8 ? 0 : length < 12 ? 1 : length < 16 ? 2 : length < 24 ? 3 : 4;
if (length >= 12 && groups >= 3)
score = Math.min(4, score + 1);
if (common || repeated)
score = Math.min(score, 1);
if (sequences)
score = Math.max(0, score - 2);
const feedback = [length < 16 && 'Use uma senha mais longa ou uma frase de acesso.', (common || sequences) && 'Evite palavras comuns e sequências previsíveis.', repeated && 'Evite padrões repetidos.'].filter(Boolean);
return { nivel: ['Muito fraca', 'Fraca', 'Moderada', 'Forte', 'Muito forte'][score], pontuacao: score, maximo: 4, caracteres: length, orientacoes: feedback, metodo: 'Estimativa heurística local; não consulta vazamentos ou dicionários completos.' };
}
async function runSecurityTool(kind, values) {
if (!crypto.subtle)
throw new Error('Esta ferramenta requer Web Crypto em HTTPS ou localhost.');
if (Object.values(values).some(value => value.length > 1000000))
throw new Error('Limite de entrada: 1 milhão de caracteres por campo.');
{
return { text: JSON.stringify(assessPassword(values.password ?? ''), null, 2), message: 'Estimativa heurística; não garante resistência contra todos os ataques.' };
}
}
return await runSecurityTool("password-strength", values);
}
import re
import json
def executar(values=None):
values = {'password': 'UmaSenha!2026Exemplo'} if values is None else values
if not isinstance(values, dict) or any(not isinstance(v,str) or len(v.encode('utf-16-le',errors='surrogatepass')) // 2 > 1000000 for v in values.values()): raise ValueError('Informe campos textuais de até 1 milhão de caracteres')
def integer(key):
raw = values.get(key,'')
if not re.fullmatch(r'[0-9]+',raw): raise ValueError('Informe inteiro válido: ' + key)
return int(raw)
password = values.get('password','')
length = len(password)
groups = sum(bool(re.search(pattern,password)) for pattern in ('[a-z]','[A-Z]','[0-9]','[^a-zA-Z0-9]'))
common = bool(re.fullmatch(r'(password|senha|admin|qwerty|letmein|welcome|123456|abc123)([0-9]|[!@#$])*',password,re.I))
repeated = bool(re.fullmatch(r'(.{1,4})\1+',password))
sequences = bool(re.search(r'012345|123456|234567|abcdef|qwerty|asdfgh',password,re.I))
score = 0 if length < 8 else 1 if length < 12 else 2 if length < 16 else 3 if length < 24 else 4
if length >= 12 and groups >= 3: score = min(4,score+1)
if common or repeated: score = min(score,1)
if sequences: score = max(0,score-2)
feedback = []
if length < 16: feedback.append('Use uma senha mais longa ou uma frase de acesso.')
if common or sequences: feedback.append('Evite palavras comuns e sequências previsíveis.')
if repeated: feedback.append('Evite padrões repetidos.')
result = {'nivel':['Muito fraca','Fraca','Moderada','Forte','Muito forte'][score],'pontuacao':score,'maximo':4,'caracteres':length,'orientacoes':feedback,'metodo':'Estimativa heurística local; não consulta vazamentos ou dicionários completos.'}
return {'text':json.dumps(result,ensure_ascii=False,indent=2), 'message':'Estimativa heurística; não garante resistência contra todos os ataques.'}
<?php
function executar($values = ['password'=>'UmaSenha!2026Exemplo']) {
foreach ($values as $value) if (!is_string($value) || strlen($value)>1000000) throw new InvalidArgumentException("Informe campos textuais de até 1 milhão de bytes");
$integer = function ($key) use ($values) { $raw = $values[$key] ?? ""; if (!preg_match("/^[0-9]+$/D",$raw)) throw new InvalidArgumentException("Inteiro inválido: " . $key); return (int)$raw; };
$password = $values['password'] ?? ''; $length = preg_match_all('/./us',$password);
if ($length === false) throw new InvalidArgumentException('UTF-8 inválido');
$groups=0; foreach (['/[a-z]/','/[A-Z]/','/[0-9]/','/[^a-zA-Z0-9]/'] as $pattern) if (preg_match($pattern,$password)) $groups++;
$common=preg_match('/^(password|senha|admin|qwerty|letmein|welcome|123456|abc123)([0-9]|[!@#$])*$/iD',$password); $repeated=preg_match('/^(.{1,4})\1+$/uD',$password); $sequences=preg_match('/012345|123456|234567|abcdef|qwerty|asdfgh/i',$password);
$score=$length<8 ? 0 : ($length<12 ? 1 : ($length<16 ? 2 : ($length<24 ? 3 : 4)));
if ($length>=12 && $groups>=3) $score=min(4,$score+1); if ($common || $repeated) $score=min($score,1); if ($sequences) $score=max(0,$score-2);
$feedback=[]; if ($length<16) $feedback[]='Use uma senha mais longa ou uma frase de acesso.'; if ($common || $sequences) $feedback[]='Evite palavras comuns e sequências previsíveis.'; if ($repeated) $feedback[]='Evite padrões repetidos.';
$result=['nivel'=>['Muito fraca','Fraca','Moderada','Forte','Muito forte'][$score],'pontuacao'=>$score,'maximo'=>4,'caracteres'=>$length,'orientacoes'=>$feedback,'metodo'=>'Estimativa heurística local; não consulta vazamentos ou dicionários completos.'];
return ['text'=>preg_replace_callback('/^( +)/m',fn($match)=>str_repeat(' ',strlen($match[1])/2),json_encode($result,JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR)), 'message'=>'Estimativa heurística; não garante resistência contra todos os ataques.'];
}