1
respuesta

INICIO DE SESION UTILIZANDO CONTROLES DEL FORM

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>INICIO DE SESION</title>
</head>
<body>
    <h1>PROGRAMA | INICIO DE SESION</h1>
    <form>
        <label>Ingrese su usuario: </label><input type="text" id="name"><br><br>
        <label>Ingrese su contraseña: </label><input type="password" id="password"><br><br>
        <button onclick="inicioSesion()">INGRESAR</button>
    </form>

     <script>
     function inicioSesion(){
        var inicioDeSesionRegistrado = "alura";
        var contrasenhaRegistrada = "alura321";
        var intentos = 1;
        var maxintentos = 3;

        while(intentos <= maxintentos){
            var inicioDeSesionIngresado = document.getElementById("name").value;
            var contrasenhaIngresada = document.getElementById("password").value;

            if( inicioDeSesionRegistrado == inicioDeSesionIngresado && contrasenhaRegistrada == contrasenhaIngresada ) {
                alert("Bienvenido al sistema " + inicioDeSesionIngresado);
                break;
            } else {
                if (intentos == 3) {
                    alert("Cantidad maxima de intentos agotada");
                }else{
                    alert("Inicio de sesión inválido. Quedan " + (maxintentos-intentos);
                }
            }
            intentos++;
        }
    }
    </script>
</body>
</html>
1 respuesta

Excelente.