0
@XmlElement(name = "Emp", type = UserBean.class)
        @XmlElementWrapper(name = "Emps")
        private List<UserBean> users;       

 if (users.stream().anyMatch(x -> x.getUsername().equals(userBean.getUsername()))
                    && users.stream().anyMatch(x -> x.getPassowrd().equals(userBean.getPassowrd()))) {
                login=true;
    }

This function checks whether a password and name exist in a container. I fill the container from xml file. However, that only check that items are existing, not the matching.

xml:

        <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Department>
        <Emps>
            <Emp>
                <username>Name</username>
                <password>name</password>
            </Emp>
            <Emp>
                <username>Name2</username>
                <password>name2</password>
            </Emp>

    </Emps>
</Department>

So I can enter username Name and the password name2 and login still will be true. Are they any ways to set login to true only if username and password are matching?

Fingolfin
  • 27
  • 5
  • 1
    [Don't use `String`s for passwords](https://stackoverflow.com/questions/8881291/why-is-char-preferred-over-string-for-passwords). – Turing85 May 07 '18 at 21:00

1 Answers1

2

Just merge the conditions into a single predicate:

if (users.stream().anyMatch(x -> x.getUsername().equals(userBean.getUsername())
        && x.getPassowrd().equals(userBean.getPassowrd())))
shmosel
  • 49,289
  • 6
  • 73
  • 138