simple membership login website code in javascript

index.tsx
// Simplified example of a membership login website using JavaScript

// This would be your database holding user information
const users = [
  { username: 'user1', password: 'password1' },
  { username: 'user2', password: 'password2' }
];

// Function to check if the input credentials are valid
function checkCredentials(username, password) {
  return users.some(user => user.username === username && user.password === password);
}

// Function to handle login button click
function handleLogin() {
  const username = document.getElementById('username').value;
  const password = document.getElementById('password').value;

  if (checkCredentials(username, password)) {
    alert('Login successful!');
    // Redirect to a new page or perform any other actions
  } else {
    alert('Invalid username or password. Please try again.');
  }
}
842 chars
26 lines

In this code snippet, we have a simple membership login website example using JavaScript. This code includes a function checkCredentials to verify the entered username and password against predefined users. The handleLogin function is called when the login button is clicked, which retrieves the entered username and password from input fields and validates them using checkCredentials. It then shows an alert message based on the success or failure of the login attempt.

gistlibby LogSnag