0

Here is the code, I want to figure out how I can access all the passwords in the API(Data) to check if the password the user puts in is equal to any of the ones I get back from an API

I was using a loop but I figured it would take too long if the database got really large, if there is another way to do this please help me!

    const Data = [{
        id: 1
        email: "ethan@gmail.com",
        password: "hey1234"
    },
    {
        id: 2
        email: "gonz42@gmail.com",
        password: "1234"
    }
    ]

for (const iterator of Data) {
            if (password !== iterator.password) {
                console.log('please enter a  password')
                setPasswordError(true)

            } else if(password === iterator.password) {
                console.log('password is valid');
                setPasswordError(false)
            }else {
                console.log('please enter a valid password')
            }

        }
Ethan
  • 17
  • 3
  • 1
    If this is for authentication, I'd think it'd make more sense to ask the user for their email or ID, then validate that against their one password, than to allow any password anyone uses. (abc123 and hunter2, here we come) Also don't store passwords in plaintext – CertainPerformance Nov 29 '22 at 05:08
  • @CertainPerformance Deep night in Texas! – flyingfox Nov 29 '22 at 05:15

0 Answers0