Struggling to create a login page with javascript? Consider using an array of usernames and passwords for verification. Check out the code below for guidance:
Taris
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
</style>
</head>
<body>
<script src="login.js"></script>
<input type="username" id="myText" value="">
<input type="password" id="myText1" value="">
<button id="button">login</button>
<script>
var userArray = [
{
username: "user1",
password: "pw1"
},
{
username: "user2",
password: "pw2"
},
{
username: "user3",
password: "pw3"
}
]
function loginFunction () {
var username = document.getElementById("myText").value;
var password = document.getElementById("myText1").value;
for(i = 0; i < userArray.length; i++){
if(username == userArray[i].username && password == userArray[i].password){
alert("Hello");
}
}
}
const button = document.getElementById("button");
button.addEventListener('click', () => {
loginFunction();
});
</script>
</body>
</html>