Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda