1 Replies - 1139 Views - Last Post: 05 March 2012 - 11:26 AM

#1 lnc12  Icon User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 268
  • Joined: 21-May 08

Trying to verify a user, but my check functions don't works

Posted 04 March 2012 - 03:38 AM

I am starting to learn using JSF and Beans, but I am having a problem, with my verify method, my verify code is like this:
public String verifyUser2(){
	   ArrayList<User> users = new ArrayList<User>(service.getUsers());
	   String dir ="error";
	   boolean found = false;
	   int i = 0;
	   while(!found && i < users.size()){
		   User u = users.get(i);
		   if(u.getName().equals(name) && u.getPassword().equals(password)){
			   found = true;
	   return dir;

And the way I call it is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml"
               <td><h:inputText value="#{userBean.name}"/></td>
               <td><h:inputSecret value="#{userBean.password}"/></td>
         <p><h:commandButton value="#{msgs.login}" action="#{userBean.verifyUser2}"/></p>

But for some reason I newer find the user and I use the sysout's to check if the username and password is the correct once and from what I can se I do type in the correct one. Can anyone tell me why I never get true returned. Am I calling something wrong or what?
Pleas tell if you need more of my code

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to verify a user, but my check functions don't works

#2 cassiopeia  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 86
  • Joined: 03-April 11

Re: Trying to verify a user, but my check functions don't works

Posted 05 March 2012 - 11:26 AM

i think you should query for only specific user that being typed in login form, not all of them. so the method should be service.getUsers(String _userId) or something like that.

//find only user typed in login form
ArrayList<User> users = new ArrayList<User>(service.getUsers("XYZ"));

for( int i=0; i<users .size(); i++ ) {    
     User u = (User) users.get(i);

     //do authenticate password

hopefuly that help, if not try visit this link, there is a authenticate() method there, you could learn more there

cheers :gun_bandana:

This post has been edited by cassiopeia: 05 March 2012 - 11:30 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1