Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
How can i verify that a element is in my array?

I'm making a simple login system for a school project and I need to verify if the usernames and passwords are in my list, but i can't seem to figure it out

var logs = [
    {
        username: "admin",
        senha: "admin"
    },

    {
        username: "client",
        senha: "client"
    }
]


function login_func() {
    let user =  document.getElementById('email_val')
    let passwd =  document.getElementById('passwd')

    if(logs.includes(user.value)){
        alert('amogus')
    }
    
}

If anyone could help I'd be really thankfull

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

the best practice for this one will be the some prototype of an array:


    function isVerify(username, password){
    
        return logs.some(log => log.password === password && log.username === username)

    }

Of course, in the real world, you will encrypt passwords, and store them in DBs.

In case you want to return the logged-in user, use find instead:


    function login(username, password){
    
        return logs.find(log => log.password === password && log.username === username)

    }

This will return null in case of unmatch result.

about 4 years ago · Juan Pablo Isaza Report

0

If you want the equivalent of includes but you need to check for a property of each object, use Array.some which takes a test function.

if (logs.some(obj => obj.username === user.value && obj.senha === passwd.value)) {

Of course, keep in mind that this type of 'authentication' will only serve for demonstration purposes and will never actually be useful for a real login.

about 4 years ago · Juan Pablo Isaza Report

0

You can use find() method to find your user exists with your inputs.

const haveUser = (username, password) => !!logs.find(log => log.username == username && log.senha === password)

Important : When we wanna create an authentication system, should not create it on the Frontend side. It's completely wrong and risky because other developers open Dev Tools and can find your credentials.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!