Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
Login system that checks out if the user already has an account. If they have one then they get to login, if they don't then they must try again

My overall problem is actually finding the values of the variables ''loginEmail'' and ''loginPass'' inside my ''arrayRegistros''. It only becomes TRUE when I write the email and password inside includes manually, however, it always ends up turning into FALSE when I use the variables themselves. I tried converting the variables into strings, then used document.getElementById alongside a few other ideas but until now, none of them completed the login system I had planned. The help I need is how one can find a certain variable's value/object, inside a certain array.

login(registro){

            this.arrayRegistros;
            var loginEmail = document.getElementById('userEmail'); 
            var loginPass =  document.getElementById('userPass');

            var contaEmail = this.arrayRegistros.some((loginEmail) => {
                return loginEmail.emailRegistro.includes(loginEmail)
            })
            var contaPass = this.arrayRegistros.some((loginPass) => {
                return loginPass.passRegistro.includes(loginPass)
            })
            
            console.log(contaEmail)
            console.log(contaPass)
            
        }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The first problem is that you are naming the parameter on the Array.prototype.some function the same as the variable you want to check outside of the predicate scope.

Second, suposing that this.arrayRegistros is a array with objects with the keys emailRegistro and passRegistro containing strings, DOM Elements CANNOT match with strings, but a element.value can.

Another thing you should have in mind is that includes is not an equality operator, 'a-very-strong-password'.includes('a'); will return true.

And, last, you should never validate login and password on the browser, because the user can edit the JavaScript code on-the-fly and get to login without any real credential.

With that in mind, I think the solution would be something like that (ignoring the browser validation problem):

const $userField = document.getElementById('userEmail');
const $passField = document.getElementById('userPass');

const registros = [
  {
    email: 'example@example.com',
    password: 'a-very-strong-password'
  },
  ...anotherUsers
]; 

function login(registro) {
  const { value: user } = $userField;
  const { value: pass } = $passField;
  
  // You can use `Array.prototype.some` to just know if the specific user credentials exist, or use `Array.prototype.find` to know if exist AND grab the user, to further utilization
  const item = registros.find(item => item.email === user && item.password === pass);

  if (item) {
    // User found
  } else {
    // User not found
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

you should get values from inputs like this:

const data = [
   {
     user : 'jhon',
     password : 'asdf123'
   },
    {
     user : 'bob',
     password : 'asdf124'
   }
 ]
const userName = document.getElementById('userEmail').value;
const passWord= document.getElementById('userPassword').value;
const findUser = data.filter( item => item.user === userName && item.password === passWord);
if(findUser.length > 0){
  //user found
 }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda