Skip to content

Instantly share code, notes, and snippets.

@rafaelbriet
Created January 16, 2020 18:54
Show Gist options
  • Save rafaelbriet/2a8fe657b5d2e5ffada3c9d96c951e9b to your computer and use it in GitHub Desktop.
Save rafaelbriet/2a8fe657b5d2e5ffada3c9d96c951e9b to your computer and use it in GitHub Desktop.
/****************************************************************************************************
Originally created by Kay and published in CodePen (https://codepen.io/opensoorce/pen/KQmvdL).
The original code used jQuery, I just converted to Vanilla JavaScript.
Just to be very clear, this code should not be used in production,
its only purpose is for testing and demos.
****************************************************************************************************/
document.addEventListener("DOMContentLoaded", function() {
let loginSubmit = document.querySelector(".login__submit-btn");
// Valid username and password
let validUsername = 'admin';
let validPassword = '123';
loginSubmit.addEventListener("click", function() {
// Prevent PageReLoad
event.preventDefault();
let loginUsername = document.querySelector(".login__input-username").value === validUsername;
let loginPassword = document.querySelector(".login__input-password").value === validPassword;
// If username and password are valids log in, else show an error message
if(loginUsername === true && loginPassword === true) {
// Redirect the user to another page
window.location = 'http://example.com/';
console.log("Loged in...");
} else {
console.log("Wrong username or Password...");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment