JSFiddle - React, Tailwind, and code Playground

by Wendell Christian

JavaScript

function findPaswword(password, name) {

    const weakPassword= ["123456", "123456789", "qwerty", "password", "1234567", "12345678", "12345", "iloveyou", "111111", "123123"];
    
    let specialCharacters = "!@#$%^&*(),.<>;'`~[]{}\\|/?_-+=";
    specialCharacters = specialCharacters.split("");
    
    const passwordCharacters = password.split("");
    
    const hasPassword = weakPassword.indexOf(password);
    
    const hasSpecialCharacter = specialCharacters.some(el => passwordCharacters.includes(el));
    
    const hasLetter = /[a-z]/.test(password);
    
    const hasUpperLetter = /[A-Z]/.test(password);
    
    const hasDigit = /[0-9]/.test(password);
    
    const hasName = password.toLowerCase().includes(name.toLowerCase());
    
    const hasRepeatedSequence = /[0-9]{2,3}/.test(password);

    if((hasPassword === -1) && (password.length > 15 && hasLetter && hasUpperLetter && hasDigit && hasSpecialCharacter && !hasName && hasRepeatedSequence) ) {
        console.log("senha valida")
    } else {
        console.log("senha invalida")
    }
}

findPaswword("12345", "Teste");
findPaswword("teste", "Teste");
findPaswword("senha@", "Teste");
findPaswword("12345678teste@aa", "Teste");
findPaswword("12345678Teste@aa", "Wendell");
findPaswword("121212Teste@aa", "Wendell");