“Wygeneruj silne hasło” Kod odpowiedzi

Wygeneruj losowe hasło

var btn = document.getElementById("btn");

btn.addEventListener("click", function generate() {
  var generatePassword = "";
  var password = document.getElementById("password");
  var characters =
    "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*?";

  for (var i = 0; i < 10; i++) {
    generatePassword += characters.charAt(
      Math.floor(Math.random() * characters.length)
    );
  }
  password.innerHTML = generatePassword;
});
Nitria

Wygeneruj losowe hasło

const generatePassword = (length = 10, specialChars = true) => {
    const alphaCodesArray = Array.from(Array(26)).map((e, i) => i + 65);
    const uppercaseAlphabetArray = alphaCodesArray.map((letterCode) => String.fromCharCode(letterCode));
    const lowercaseAlphabetArray = uppercaseAlphabetArray.map(e => e.toLowerCase());

    const uppercaseAlphabet = [...uppercaseAlphabetArray].join('');
    const lowercaseAlphabet = [...lowercaseAlphabetArray].join(''); 
    const numbers = [...Array(10).keys()].join('');
    const specialSymbols = typeof specialChars === 'string' ? specialChars : (specialChars ? "!@#$%^&*?" : "");
    
    const characters = `${lowercaseAlphabet}${numbers}${uppercaseAlphabet}${specialSymbols}`;

    return [...Array(length).keys()].reduce(acc => acc.concat(characters.charAt(Math.floor(Math.random() * characters.length))), '');
}
nilso

Wygeneruj silne hasło

# Generate strong password
import random
import string


def generate_password(length):
    """
    Generate strong password with length

    Args:
        length (int): length of password

    Returns:
        password (str): strong password
    """
    password = ''
    for i in range(length):
        password += random.choice(string.ascii_letters + string.digits)
    return password


def main():
    length = int(6)  # length of password
    password = generate_password(length)
    print(password)


if __name__ == '__main__':
    main()
Ugly Unicorn

Odpowiedzi podobne do “Wygeneruj silne hasło”

Pytania podobne do “Wygeneruj silne hasło”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu