HTML code script for a Bcrypt generator.

Created on 3 July, 2024 • 113 views • 1 minutes read

HTML code script for a Bcrypt generator.

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <title>Bcrypt Generator</title>

</head>

<body>

  <h1>Bcrypt Generator</h1>

  <p>Enter your password to generate a secure Bcrypt hash:</p>

  <form id="hashForm">

    <label for="password">Password:</label>

    <input type="password" id="password" name="password" required>

    <br>

    <button type="submit">Generate Hash</button>

  </form>

  <p id="hashResult"></p>


  <script>

    document.getElementById('hashForm').addEventListener('submit', function(event) {

      event.preventDefault();

      const password = document.getElementById('password').value;

      fetch('/generateHash', {

        method: 'POST',

        body: JSON.stringify({ password }),

        headers: { 'Content-Type': 'application/json' }

      })

      .then(response => response.json())

      .then(data => {

        document.getElementById('hashResult').textContent = `Hashed Password: ${data.hash}`;

      })

      .catch(error => {

        console.error(error);

        document.getElementById('hashResult').textContent = 'Error generating hash.';

      });

    });

  </script>

</body>

</html>